Hi
I am trying to use a custom attribute that takes in an array or list of
custom objects. Ths custom object has a text property and a type property.
I have a custom attribute which has a constructor that takes a class as
follows:
================================================== =====
Public Class MyAttribute
Inherits System.Attribute
Private m_Variables As Generic.List(Of NameValuePair)
Public Sub New(ByVal variableToAdd As NameValuePair)
Me.m_Variables = New Generic.List(Of NameValuePair)(New
NameValuePair() {variableToAdd})
End Sub
End Class
Public Class NameValuePair
Public Name As String
Public Type As Type
End Class
================================================== =====
However, when I try to use the attribute I get a "constant expression is
required" error.
================================================== =====
<MyAttribute(New NameValuePair("Text", GetType(Boolean)"))> _
Public Property MyProperty As Boolean
[...]
================================================== =====
I'm pretty sure I would be able to acheive the same thing by using two
seperate lists.
================================================== =====
Public Sub New(ByVal names As String(), ByVal values As object())
================================================== =====
and then just ensure that the count of each array match but this can't be a
good way of doing it.
Can anyone suggest a solution that uses VB.NET?
Regards, Carl Gilbert