2011-09-28 3 views
4

몇 가지 필드로 사용자 지정 유형이 있는데, 종속성 속성 만 가져오고 싶습니다.리플렉션 (Type.GetProperties)을 사용하여 DependencyProperties를 가져 옵니까?

propertyInfos = myType.GetProperties(); 

foreach (PropertyInfo propertyInfo in propertyInfos) 
{ 
    Console.WriteLine(propertyInfo.Name); 
} 

은 내가 BindingFlags.XXX와 GetProperties를위한 매개 변수, somethg에 무언가를 추가 할 필요가 알고 있지만 내가 XX로 가능한 모든 것을 확인하지 않았다 : 여기

모든 속성을 반환하는 코드입니다

+0

는 종속성 속성의 두 가지 측면이 있습니다 : 해당 컨트롤의 부모의 종속성 속성이 너무 당신은 다음과 같은 방법을 사용할 수 있습니다 (이것은'유형 인 실제 종속성 속성입니다 정적 * 필드 *를 DependencyProperty') 및 정적 필드의 값을 반환하는 facade 속성 무엇을 돌려주고 싶니? –

답변

5

종속성 속성 당신이 얻고 싶은 경우에 유형 DependencyProperty

static IEnumerable<FieldInfo> GetDependencyProperties(Type type) 
{ 
    var dependencyProperties = type.GetFields(BindingFlags.Static | BindingFlags.Public) 
            .Where(p => p.FieldType.Equals(typeof(DependencyProperty))); 
    return dependencyProperties; 
} 

의 정적 필드입니다 ... 나에게 좋은 소리 뭔가를 찾아

static IEnumerable<FieldInfo> GetDependencyProperties(Type type) 
{ 
    var properties = type.GetFields(BindingFlags.Static | BindingFlags.Public) 
         .Where(f=>f.FieldType == typeof(DependencyProperty)); 
    if (type.BaseType != null) 
     properties = properties.Union(GetDependencyProperties(type.BaseType)); 
    return properties; 
} 
관련 문제