Re: C# inheritance broken?



Tom,

Do you have a an example of how to do this with reflection?

Mike Ober.

"Tom Shelton" <tom_shelton@xxxxxxxxxxxxxxxxxx> wrote in message
news:XqGdnV7R6qfTjyHYnZ2dnUVZ_oWdnZ2d@xxxxxxxxxxxxxx
On 2007-01-27, Bruce Wood <brucewood@xxxxxxxxxx> wrote:
A generalized method of converting a base class into a derived class
with
the knowledge that the derived class may still require some
initialization
would definitely be useful, even if you had to do it via a constructor
that
takes an object of the base class as it's argument. The missing syntax,
in
vb is

mybase = objBaseClass

In C# I think it would be

base = objBaseClass

In either case, since this is occurring in a constructor in place of the
base.New() or mybase.New statement, the programmer knows he still has to
instantiate and initialize all other private and protected objects in
the
derived class.

Mike Ober.

Agreed. That would be nice. I wouldn't need it often, but it would get
one out of some tricky corners. My only point was that the whole "I
have a base class instance and I want to treat it as though it were a
derived class instance" is completely unsafe and therefore runs
against the grain of what .NET is supposed to be all about. Being able
to copy state, though, would be handy.


Reflection :)

--
Tom Shelton


.



Relevant Pages

  • Re: Call a function from another page
    ... derived class (actually I believe you could do this using reflection but it ... GetID() as string>. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Invoking method with generic parameters
    ... - GetType*cannot* be used to call private method in derived class!!! ... Addcall from code works but Addcall from reflection does not work! ... They only exist in the declaring type, so there'd be no way to return them reflecting on derived types. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: c# call virtual/abstruct function from the constructor of the base class
    ... In general, it's a bad practice to call members in a derived class, ... However, I think, my situation warrants to break ... In practice, if you're very careful, you can get away with it. ... But IMHO it's better to, in these situations, provide a post-constructor initialization method that does the polymorphic work. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: diamond inheritance hides non-default constructor
    ... I finally found your quote in the std doc under initialization, ... the constructor of the most derived class. ... initialize the virtual base class subobject. ...
    (comp.lang.cpp)
  • Re: C# inheritance broken?
    ... the knowledge that the derived class may still require some ... takes an object of the base class as it's argument. ... derived class instance" is completely unsafe and therefore runs ...
    (microsoft.public.dotnet.languages.csharp)

Loading