Re: Expose members of contained class



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
.



Relevant Pages

  • Re: Custom Serializable Objects
    ... my own custom objects which are for all intensive purposes an Interface ... IDE so happy to auto generate and overwrite any custom code you have written ... There has got to be a way for WSDL ... As for the remoting, I know what remoting is capable of ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Design Problem Aggregation
    ... >Class E has a member of type A. ... As D is the base class of E and F we can add to the container ... >that interface in E and F. A and B have many member functions and I ... This is called the Interface Segregation Principle. ...
    (comp.object)
  • Re: Best of breed PDM
    ... good SolidWorks integration, good customizability, and great tech ... decent interface and good functionality for its price. ... write custom apps for it, ... > What is the best PDM system for Solidworks. ...
    (comp.cad.solidworks)
  • Re: Another great example of how Word 2007 "brings commands closer to the surface"
    ... trashing and replacing Word's total interface and method of operation was ... remake the entire Word user interface to produce these new features? ... since the "majority" of users don't create custom toolbars and ... Hey, folks, the "majority" of users also never create a macro, ...
    (microsoft.public.word.newusers)
  • Re: abstract class does not implement interface member ...
    ... saying that a protected member can not expose an internal ... Why can't I return an internal interface from a protected member ... internal interface IInvocableInternals: IInvocable ...
    (microsoft.public.dotnet.languages.csharp)