Re: Expose members of contained class
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 15 Apr 2009 11:15:23 -0700
On Wed, 15 Apr 2009 07:44:09 -0700, <hvj@xxxxxxxxxx> wrote:
Hi all,
Is it possible to 'automatically' expose the members of a contained
class in C# (just as with COM) that implements some interface that
that the containing class wants to implement by delegating to the
contained class? Off course it is possible to implement all the
properties and methods in the containing class by calling the same
property on the contained class, but if it is possible I would like to
avoid that.
I thought maybe with the new possibilities with dynamic methods, class
extension etc this might be possible.
Not that I know. Certainly without C#/.NET 4.0's dynamic type it wouldn't be possible. Even with that, you would still need to write some sort of custom binder that uses a custom mechanism in your type to retrieve the implementation interface for the type. The mechanism would have to demand the interface implementation from the containing class, and somehow map the method call to the contained implementation. I haven't seen anything that would suggest that's going to be a language feature, which means you'd have to dive into the DLR internals to provide that functionality (assuming it's possible at all...I don't know to what degree customization is even possible).
Another possibility would be generating the code that implements the
properties and methods. A sollution in that direction would also be
appreciated.
I'm not aware of any. Of course, you can have Visual Studio generate all the stubs. It's possible you can customize what it generates; I think VS uses the "snippets" feature to do that work, so I suppose you could replace the stock "snippet" (which just inserts a bunch of "throw new NotYetImplementedException()" statements with one that calls some default instance member. Then you'd just have to make sure that instance member is defined.
But again, I don't the specifics as to how you'd do that.
Pete
.
- References:
- Expose members of contained class
- From: hvj
- Expose members of contained class
- Prev by Date: Re: Expose members of contained class
- Next by Date: Re: Stopping List.ForEach in C# 2.0
- Previous by thread: Re: Expose members of contained class
- Next by thread: Re: Expose members of contained class
- Index(es):
Relevant Pages
|