2016-06-08 5 views
0

두 구조와 하나의 클래스가 내 네임 스페이스 Dimension에 있습니다. 이러한 구조는 Dimension.DerivedDimension.Basis입니다. 수업은 Exponent이라고합니다. 내 클래스의 ToString() 함수를 오버라이드하여 DisplayNameAttribute의 속성을 내 구조에 넣었습니다. Dimension.Derived.두 개의 PropertyInfo 병합

Public Overrides Function ToString() As String 

    Dim oType As Type 
    oType = GetType(Dimension.Derived) 

    Dim colMemberInfo() As PropertyInfo = oType.GetProperties 

    For Each oMemberInfo In colMemberInfo 
     If Me = oMemberInfo.GetValue(oMemberInfo) Then 
      Dim de As New Dimension.Exponent 
      de = oMemberInfo.GetValue(oType) 
      Dim attr() As DisplayNameAttribute = DirectCast(oMemberInfo.GetCustomAttributes(GetType(DisplayNameAttribute), False), DisplayNameAttribute()) 
      If attr.Length > 0 Then 
       Return attr(0).DisplayName 
      Else 
       Exit For 
      End If 
     End If 
    Next 

    Return Nothing 

End Function 

잘 작동하지만 두 구조를 모두 검색해야합니다. 따라서, 나는

Dim oType1, oType2 As Type 
oType1 = GetType(Dimension.Derived) 
oType2 = GetType(Dimension.Basis) 

Dim colMemberInfo() As PropertyInfo = oType1.GetProperties And oType2.GetProperties 

에 첫 선을 변경하지만이 And - 연산자가 PropertyInfo 선언되지 않는다는 예외가 발생합니다. 확실히 For-Each-loop를 다른 구조에 대해 반복 할 수는 있지만 그 의도는 아닙니다. 이 PropertyInfo를 병합하려면 어떻게해야합니까?

답변

1

And은 부울 연산자입니다. True/False 값입니다. 두 가지 유형 중 PropertyInfo 목록을 얻으려고하므로 다음을 시도하십시오.

Dim properties as List(Of PropertyInfo) = New List(Of PropertyInfo) 
properties.AddRange(oType1.GetProperties()) 
properties.AddRange(oType2.GetProperties())