Re: How to access private members of a base class
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 24 Oct 2005 11:16:50 -0400
Abelardo,
If you have the type of the class, you can use the BaseType property to
get the base class. You can then use reflection on that type to get the
private members, and so on, and so on...
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Abelardo Vacca" <AbelardoVacca@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DDFAFF00-58E5-4452-B933-E28E767B5D58@xxxxxxxxxxxxxxxx
> Thank you,
> Perhaps i should have been more explicit in my question.
>
> I already use reflection, and it works half-way: Without
> ReflectionPermission you cannot access the non-public members of a class (
> that's why I wrote I had that permission out of the way)
> Now, WITH ReflectionPermission, I can access ALL members, but ONLY on the
> current class level. But I CANNOT obtain the PRIVATE members of the base
> classes. (That is normal, because private members of a base class are NOT
> members of the derived classes) - PROTECTED members are available, even if
> they are declared on base classes -
>
> I would like to know if there is a way around this.
>
> Thank you
>
> "Nicholas Paldino [.NET/C# MVP]" wrote:
>
>> Abelardo,
>>
>> You will only be able to access this information through reflection,
>> getting the MethodInfo instances representing the private methods, and
>> then
>> calling Invoke on them (using the instance of the object).
>>
>> If you have access to the code of the class, you might want to
>> consider
>> exposing the methods as public/internal/protected (depending on where the
>> method calls are taking place).
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Abelardo Vacca" <AbelardoVacca@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
>> message
>> news:D414B0C6-3CCE-4290-A83F-D94964380A34@xxxxxxxxxxxxxxxx
>> > Hi,
>> > The title sums up the question pretty much.
>> > I would like to access all private members of a class including the
>> > private
>> > members of its base classes.( I already have the ReflectionPermission )
>> >
>> > Is there a way to get this information ?
>> >
>> > Thnaks in advance
>>
>>
>>
.
- Prev by Date: Re: how is performance impact of adding extra methods to a class.
- Next by Date: Re: Casting types when having the System.Type
- Previous by thread: Re: how is performance impact of adding extra methods to a class.
- Next by thread: Re: How to access private members of a base class
- Index(es):
Relevant Pages
|