<AttributeUsage(AttributeTargets.Property)> _
Private Class CustomAttrib
Inherits Attribute
Public Property DataTypeLength As Integer
End Class
Private Class TestClass
<CustomAttrib(DataTypeLength:=75)> _
Public Property MyProp As String
End Class
Dim properties = GetType(TestClass).GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
For each Prop As FieldInfo in Properties
Dim attributes = DirectCast(prop.GetCustomAttributes(GetType(TestClass), False), CustomAttrib())
If Attributes.Any Then
'get value of custom attribute
End If
Next
Ok no matter what i do attributes is always null/nothing. I have also tried the following also:
Attribute.GetCustomAttributes(prop)
This returns two attributes of type CompilerGeneratedAttribute
and DebuggerBrowsableAttribute
What am i doing wrong here?