0

Im extending a class (DirectoryServices.AccountManagement.Principal) and I need to assign a value to a field in the base class but its marked internal. Can I use reflection to set the value? How would that be done?

I found this:

base.GetType().GetProperty("unpersisted").SetValue(??, false);

But im not quite sure how to give it the base Principal object

Any guidance is much appreciated.

Miles
  • 31,360
  • 7
  • 64
  • 74
Exist
  • 1,941
  • 2
  • 17
  • 14

2 Answers2

1

use this for ??

JoelFan
  • 37,465
  • 35
  • 132
  • 205
0

GetProperty on the derived class and use all parameters as this:

GetType(Derived).GetProperty("BaseProperty", BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, GetType(PropertyType), New Type() {}, Nothing).SetValue(DerivedInstance, NewValue, Nothing)
Wilhelm
  • 1,868
  • 14
  • 21