Free all resources held by an object with IDisposable

Posts   
 
    
amiweb
User
Posts: 1
Joined: 01-Sep-2004
# Posted on: 02-Sep-2004 12:54:34   

Is there a good reason why the generated classes do not implement the IDisposable interface to free all the object they contain?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 02-Sep-2004 13:00:55   

The base class implements IDisposable, there is no need to do that again in the derived class (you can't even in VB.NET), and there are no resources held in the generated code which justify IDisposable: everything is managed, so IDisposable is not needed.

Frans Bouma | Lead developer LLBLGen Pro
luciusism
User
Posts: 119
Joined: 02-Jun-2007
# Posted on: 10-Oct-2007 07:11:40   

Otis wrote:

The base class implements IDisposable, there is no need to do that again in the derived class (you can't even in VB.NET), and there are no resources held in the generated code which justify IDisposable: everything is managed, so IDisposable is not needed.

Well, I tried EntityBase2 in a using block (w/ c#) and VS gave me a compile time error:

'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2': type used in a using statement must be implicitly convertible to 'System.IDisposable'

I'd like to create multiple entity instances using the following:


using (MyEntity my = new MyEntity())
{
     my.property = X
}

using (MyEntity my = new MyEntity())
{
     my.property = y
}

using (MyEntity my = new MyEntity())
{
     my.property = z
}

The using block has the advantage that I can copy and paste the block over and over, simply changing the property values. (For my specific case, I need to init persistent storage with a set of system entities)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 12-Oct-2007 11:00:04   

Ok, though why would you need a using statement there? if you really want to set values in a block, you can always do MyEntity m = new MyEntity(); { m.PropertyX = x; ... }

Frans Bouma | Lead developer LLBLGen Pro