The syntax is admittedly ugly, though maybe with some work it could be
acceptable. One change which might help would be to have the compiler
enforce a rule that ownership must be assigned in each and every
constructor for a disposable class. This rule would be enforced instead of
alteration to the new operator.
Also, instead of two attributes (disposable and disposableowner), only one
is really needed, so that:
[disposable()]
class MyResource
{
File m_file;
// following causes compiler to generate an error as it does not assign
ownership to the created instance
public MyResource()
{
}
// following causes compiler to generate an error as it does not assign
ownership to the created instance
public MyResource(IDisposable owner)
{
}
// following is ok
public MyResource(IDisposable owner)
{
AssignOwner(owner);
}
public void OnDispose()
{
m_file.close();
}
}
Now, when using the disposable resource, the syntax becomes a little
cleaner. Still not great - I've yet to come up with an alternative to the
addition of a scope keyword, which creates a hidden instance of a 'Scope'
class.
[disposable()]
class MyExample
{
MyResource m_resource;
public MyExample(IDisposable owner)
{
m_resource = new MyResource(this);
AssignOwner(owner);
}
public void Example1()
{
MyResource firstResource = new MyResource(localscope);
scope(myScope)
{
MyResource resource = new MyResource(myScope);
}
}
}
On Tue, 5 Nov 2002 17:00:14 -0800, Chris Sells <[EMAIL PROTECTED]>
wrote:
>In spite of the DF Police, I love the idea of providing and enforcing
>disposable object ownership rules. However, what you're proposing (even
>as supported by a language directly) has a syntax so heavy-duty as to be
>prohibitive, both to understand and to use. Having said that, I don't
>have anything better...
>
>Chris Sells
>http://www.sellsbrothers.com
>http://www.develop.com
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.