2013-03-24 5 views
0

누구든지 내가 잘못하고있는 것을 볼 수 있습니까? 이 유형에는 서비스 메소드가 액세스하려고하는 공용 속성이 있으므로 리플렉션에 의해 선택되지 않는 이유는 무엇입니까?빈 배열을 반환하는 GetFields

Public class SomeClass 
{ 
    private YetAnotherClass yetAnotherClass; 

    public SomeClass(SomeOtherClass otherclass) 
    { 
     this.yetAnotherClass = otherclass.SomeProperty; 
    } 

    public YetAnotherClass SomeProperty 
    { 
     get { return this.yetAnotherClass; } 
    } 
} 

Public class ServiceClass 
{ 
    public void DoSomething(SomeClass someclass) 
    { 
     Type type = someclass.GetType(); 
     FieldInfo[] fieldsinfo = type.GetFields(BindingFlags.Public | BindingFlags.Instance); // returns empty collection 
     FieldInfo fieldinfo = type.GetField("SomeProperty"); // returns null reference exception 
    } 
} 

건배

스튜어트

+0

도움이된다면 답변을 수락 해주십시오. 고마워 – Sebastian

답변

7

SomeProperty은 - 이름이 말하는 것처럼 - 속성. 대신 GetPropertyGetProperties을 사용하십시오! 이는 FieldInfo 대신 PropertyInfo이됩니다.

관련 문제