I want to know how to change the values of my custom attributes.
The Attribute:
Attribute Setup:Code:<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True, Inherited:=True)> _ Public Class IndexAttribute Inherits System.Attribute Private _MaxLength As Integer Public Property MaxLength() As Integer Get Return _MaxLength End Get Set(ByVal value As Integer) _MaxLength = value End Set End Property Private _NotNull As Boolean Public Property NotNull() As Boolean Get Return _NotNull End Get Set(ByVal value As Boolean) _NotNull = value End Set End Property End Class
Attempt to Change Attribute Value at RunTime:Code:Public Class Index Private _Value As String <IndexAttribute(MaxLength:=0, NotNull:=False)> _ Public Property Value() As String Get Return _Value End Get Set(ByVal value As String) _Value = value End Set End Property End Class
Code:'--Get and Set the Custom Attributes for the Index object. Dim _IndexAttribute As IndexAttribute _IndexAttribute = CType(Attribute.GetCustomAttribute(_Index.GetType.GetProperty("Value"), _ GetType(IndexAttribute)), IndexAttribute) _IndexAttribute.MaxLength = 102
Even though you are allowed to change the MaxLength, it doesn't stick for the _Index instance.


Reply With Quote
