B
Born
"> A solution (but you're not going to like it) would be to do it manually
I thought about similiar things. That seems to be the only way at present if
I want to use C# to give a general purpose framework. I admit I don't like
it because inexperienced user or exception can easily ruin it.
via IDisposable. Create a proxy with the reference count and a reference
to the resource, and create handles with a reference to both the
resource and the proxy and that decrement the reference count when
disposed. Have the proxy dispose the resource when the refcount reaches
0. Only hand out handles to the resource, and (if necessary) wrap access
to the resource so that it's not visible to the outside. The handles
could have a Clone() method that creates a new handle and increments the
refcount.
That technique turns N-ownership into N instances of 1-ownership. So
theoretically, if you're able to deal with a single parent, you're able
to deal with N single parents (and thus N parents).
-- Barry
I thought about similiar things. That seems to be the only way at present if
I want to use C# to give a general purpose framework. I admit I don't like
it because inexperienced user or exception can easily ruin it.