0
클래스의 개체 속성을 설정하려고하지만 오류가 Object does not match target type
이라고 표시됩니다.C# Reflection - 속성 값 설정
FieldInfo dControl = window.GetType().GetField("dControl", BindingFlags.NonPublic | BindingFlags.Instance);
if (dControl == null) { Debug.Log ("dControl is null"); return;}
Type typeDC = dControl.FieldType;
PropertyInfo inPreviewMode = typeDC.GetProperty("InPreviewMode", BindingFlags.Public | BindingFlags.Instance);
if (inPreviewMode == null) { Debug.Log ("dControl.InPreviewMode is null"); return;}
bool value = false;
inPreviewMode.SetValue(dControl, value, null);
이것은 내가 접근에 노력하고있어 속성입니다 :
public class DControl : TimeArea
{
public bool InPreviewMode
{
get
{
return dState.IsInPreviewMode;
}
set
{
if (cutscene != null)
{
...
}
}
dState.IsInPreviewMode = value;
}
...
}
도움말이 감사합니다.
왜'dState.IsInPreviewMode = 값이 설정 값에 되었 :
그래서 당신은 반사를 통해 해당 인스턴스를 얻을해야 할 수도 있습니다 '? –
필드가 항상'DControl'의 인스턴스가 될 것으로 기대하십니까? 필드 값을 가져 와서 캐스팅 할 수 있습니다. 대신'inPreviewMode.SetValue (dControl.GetValue (window), value, null)'과 같은 것을 할 필요가 있습니다. – Lee