0

我扩展了一个类(DirectoryServices.AccountManagement.Principal),我需要为基类中的一个字段分配一个值,但它标记为内部的。我可以使用反射来设置值吗?那怎么做?

我找到了这个:

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

但我不太确定如何给它基本的 Principal 对象

非常感谢任何指导。

4

2 回答 2

1

这个??

于 2009-06-28T02:05:29.503 回答
0

GetProperty 在派生类上并使用所有参数,如下所示:

GetType(Derived).GetProperty("BaseProperty", BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, GetType(PropertyType), New Type() {}, Nothing).SetValue(DerivedInstance, NewValue, Nothing)
于 2009-06-28T03:26:47.997 回答