473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Custom Attribute - "constant expression is required"

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
Feb 27 '06 #1
0 2151

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
4
by: jaime | last post by:
Hi again all. Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) I've been...
13
by: bobg.hahc | last post by:
running access 2k; And before anything else is said - "Yes, Virginia, I know you can NOT use a variable to set a constant (that's why it's constant)". BUT - my problem is - I want a constant,...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.