【发布时间】:2016-07-12 20:33:38
【问题描述】:
我正在尝试在类中设置对象的属性,但我无法获取该属性。
FieldInfo dControl = window.GetType().GetField("dControl", BindingFlags.NonPublic | BindingFlags.Instance);
if (dControl == null) { Debug.Log ("dControl is null"); return;}
PropertyInfo inPreviewMode = dControl.GetType().GetProperty("InPreviewMode", BindingFlags.Public | BindingFlags.Instance);
if (inPreviewMode == null) { Debug.Log ("dControl.InPreviewMode is null"); return;}
inPreviewMode.SetValue(dControl, false, null);
但是,inPreviewMode 返回 null。
这是我要访问的属性:
public class DControl : TimeArea
{
public bool InPreviewMode
{
get
{
return dState.IsInPreviewMode;
}
...
}
...
}
如果重要,该类将存储为 dll。
感谢您的帮助。
【问题讨论】:
-
好吧,您目前正在尝试设置值(您正在调用
SetValue)并且您没有显示设置器......如果你会显示minimal reproducible example。
标签: c# reflection properties