views:

195

answers:

1

I am extending LINQ to SQL entity classes using partial classes, and I'm wondering how to best reset some properties on the entity objects to their default state.

My partial classes uses no unmanaged recourses. And as far as I can tell; neither does the LINQ to SQL entity classes. So I'm thinking that I'll implement IDisposable and handle the resetting of properties inside of Dispose().

  • What are your thoughts on this approach?
  • And would you set before mentioned properties to null or something else?
+2  A: 

For better or worse, IDisposable is almost universally associated with finishing with a resource rather than reseting it. This sounds like an odd use to me. I would just create a Reset() method - or just create a new instance when you need to. What's the purpose of this? What are you trying to achieve?

As for "suppress[ing] the instance on the GC" - what exactly do you mean? If you're talking about a finalizer, I'd think very carefully before adding a finalizer - it's very rarely the right way to go.

Jon Skeet
Well, I am trying to "finish" my objects. I'm just not sure how, though. The only thing I can come up with is resetting the object.
roosteronacid
Why are you trying to do this though? What's wrong with just letting them become eligible for garbage collection and let things take their course? What benefit do you expect to see?
Jon Skeet
Lets say I call Remove() on an object. The method deletes the objects associated database-entry. Now the object represents something that no longer exists (the entry in the database). I'd like the object to reflect the database entry at all times--ideally I want the object to be null after a call to Remove()
roosteronacid
An object itself can't be null. Can't you just trust your callers to not reference the object after removing it? Is this *actually* a problem for you, or are you just trying to anticipate problems?
Jon Skeet