2011-10-27 5 views
3

다음과 같은 클래스가 주어진다클래스의 속성에 지정된 속성을 읽으려면 어떻게해야합니까?

Public Class Customer 
    Inherits XPBaseObject 

    Private _CustomerID As Integer = -1 

    <Key(True), _ 
    Custom("AllowNull", "True"), _ 
    Custom("AutoInc", "True"), _ 
    DbType("int")> Public Property CustomerID() As Integer 
     Get 
      Return _CustomerID 
     End Get 
     Set(ByVal value As Integer) 
      SetPropertyValue(Of Integer)("CustomerID", _CustomerID, value) 
     End Set 
    End Property 
End Class 

CustomerID 또는 다른 속성의 사용자 정의 attibutes는 어떻게 읽을 수 있습니까?

미리 감사드립니다

답변

2

:

Dim properties As PropertyInfo() = Me.[GetType]().GetProperties() 
For Each prop As PropertyInfo In properties 
    Dim attribute As Attribute = prop.GetCustomAttributes(GetType(Attribute), True)_ 
     .OfType(Of Attribute)()_ 
     .FirstOrDefault() 
Next 
관련 문제