Re: How to access private members of a base class

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>>
>>
>>


.



Relevant Pages

  • Re: How to get value of an private member?
    ... OO is designed to prevent access to the private members, ... If reflection is only a way to discover the public members, ... be designed as a php class. ... That's not what reflection is in OO design. ...
    (comp.lang.php)
  • Re: How to get value of an private member?
    ... OO is designed to prevent access to the private members, ... If reflection is only a way to discover the public members, ... be designed as a php class. ...
    (comp.lang.php)
  • Re: Private member access.
    ... I'm not quite seeing how the reflection issue arises if type-specific ... > FieldInfo.SetValueworks perfectly well on private members. ... > assembly access to private members. ... > assemblies that I have control over - so they can be modified if ...
    (microsoft.public.dotnet.security)
  • Re: How to get value of an private member?
    ... OO is designed to prevent access to the private members, ... friend class/function i think. ... If reflection is only a way to discover the public members, ... be designed as a php class. ...
    (comp.lang.php)
  • Re: Using built in dialog boxes - how to determine arguments?
    ... > argument lists of a specific dialog with reflection? ... "Interactions with built-in Word dialog boxes are through late binding, ... You must use the Reflection libraries to ... access dialog box members." ...
    (microsoft.public.vsnet.vstools.office)