Re: Object Reference to MyBase
From: Dennis (Dennis_at_discussions.microsoft.com)
Date: 10/24/04
- Next message: PJones: "one way password encryption"
- Previous message: Ken Tucker [MVP]: "Re: TreeView Control Questions"
- In reply to: Imran Koradia: "Re: Object Reference to MyBase"
- Next in thread: Imran Koradia: "Re: Object Reference to MyBase"
- Reply: Imran Koradia: "Re: Object Reference to MyBase"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 24 Oct 2004 08:45:02 -0700
Imran, thank you very much for your time in answering my question. What I'm
trying to do is set the rowheights in class that inheirits the datagrid
control. The following works for the Datagrid class but doesn't work for
inheirited classes where dg is datagrid object (or my class that inheirits
the datagrid class). The "get_DataGridRows" is a private method, I'm told,
in the DataGrid control.
Dim mi As MethodInfo = dg.GetType().GetMethod("get_DataGridRows", _
BindingFlags.FlattenHierarchy Or BindingFlags.IgnoreCase Or _
BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or _
BindingFlags.Static)
Dim dgra As System.Array = CType(mi.Invoke(Me.dg, Nothing), System.Array)
I understand what you are saying about the private methods of the class
that's being inheirited not accessable but there must be some way to get at
the rowobject collection of the datagrid base class. I'll play around with
your reflection example some and see what I can do. Thanks again.
"Imran Koradia" wrote:
> Dennis,
>
> I don't think my previous comment would have answered your question
> completely. As I mentioned, the MyBase keyword refers to the current
> instance of the derived class. As far as private methods (or properties,
> etc) go, when a class derives from a base class, the private methods are not
> inherited and so there is nothing like accessing the private methods of the
> base class! When you look at a derived class, there's just one class - the
> derived class - that has its own members and members inherited from the base
> class. Since private members are not inherited, the derived class simply
> doesn't have them and is completely unaware of them. So there's no question
> about executing a private method of the base class in the context of the
> derived class since that doesn't make sense at all, IMO.
>
> I hope that clears things up a bit..
> Imran.
>
> "Dennis" <Dennis@discussions.microsoft.com> wrote in message
> news:2CD32FB8-DCC0-4160-AAB8-AE0134E76044@microsoft.com...
> > The base class I am inheriting is a VB.Net control and I have no control
> over
> > the scope of it's methods. Do you have any idea how I can use reflection
> to
> > get at the method of the base class? It's not an exposed method that you
> can
> > call using MyBase.baseclassmethod.
> >
> > "Imran Koradia" wrote:
> >
> > > Can you make the base class method protected? That way only the derived
> > > classes can access the method - in a way its 'private' to the base class
> and
> > > all classes that derive from it. Then you can simply call
> > > MyBase.BaseClassMethod or infact you can also call Me.BaseClassMethod
> since
> > > the derived class inherits this method.
> > >
> > > Apart from that, AFAIK, there's no direct way to access the private
> methods
> > > of the base class. You would have to resort to using Reflection to
> access
> > > the method.
> > >
> > > hope that helps..
> > > Imran.
> > >
> > > "Dennis" <Dennis@discussions.microsoft.com> wrote in message
> > > news:C82453F3-F85D-47CC-9C5C-AEA9AB32DAC3@microsoft.com...
> > > > When a class (myownclass) inheirits another class, how can I get an
> object
> > > > reference to the underlyng MyBase class instance from within
> myownclass.
> > > > The
> > > > base class has a method that I want to utilize in myownclass but the
> > > > method
> > > > is private and can't be inheirited. I need to utilize that base
> class
> > > > method.
> > > >
> > > > --
> > > > Dennis in Houston
> > >
> > >
> > >
>
>
>
- Next message: PJones: "one way password encryption"
- Previous message: Ken Tucker [MVP]: "Re: TreeView Control Questions"
- In reply to: Imran Koradia: "Re: Object Reference to MyBase"
- Next in thread: Imran Koradia: "Re: Object Reference to MyBase"
- Reply: Imran Koradia: "Re: Object Reference to MyBase"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|