2009-06-28 27 views
0

Im擴展一個類(DirectoryServices.AccountManagement.Principal),我需要給基類中的一個字段賦值,但是它的標記爲內部。我可以使用反射設置值嗎?這將如何完成?如何設置一個基類內部字段

我發現這一點:

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

但是我不太清楚如何給它的基礎主要對象

任何指導是非常讚賞。

回答

1

使用這個爲??

+0

我試過,但它的基類的IM興趣 – Exist 2009-06-28 02:17:34

0

的getProperty在派生類中,並使用所有的參數,因爲這:

GetType(Derived).GetProperty("BaseProperty", BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, GetType(PropertyType), New Type() {}, Nothing).SetValue(DerivedInstance, NewValue, Nothing) 
相關問題