Pregunta

Given the following class

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

How can I read the custom attibutes of the CustomerID or any other property?

Thanks in advance

¿Fue útil?

Solución

Using reflection:

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top