By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,887 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,887 IT Pros & Developers. It's quick & easy.

Attributes

P: n/a
I have created my attribute with the constructor as
follows:

Public Sub New(ByVal value As Object)
MyBase.New(value)
End Sub

now when I try to use it like this
<Att(1)>
it get the following error: conversion from integer to
system.object cannot occur in a constant experssion!

Note that this code runs perfectly on C#.. Any explenation
and solution plz.

Regards

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi zsilence,

|| Public Sub New(ByVal value As Object)
|| MyBase.New (value)
|| End Sub

This will work
Public Sub New (Value As Integer)

As to why there is a conversion error, I do not know.

I'm puzzled by your MyBase.New (value). What Attribute class are your
inheriting from ? The base class Attribute doesn't take parametres in its
New().

You say it works in C#. Can you show me your Attribute class in C# and in
VB?

Regards,
Fergus
Nov 20 '05 #2

P: n/a
Here is my structure:
I have this attribute:
<AttributeUsage(AttributeTargets.Property Or
AttributeTargets.Field)> Public NotInheritable Class
GreaterThan
Inherits ComparisonConstraint

here is its constructor:
Public Sub New(ByVal value As Object)
MyBase.New(value)
End Sub 'New
I need to pass an object cause it is a generic one.

The base class is as follows:
<AttributeUsage(AttributeTargets.Property Or
AttributeTargets.Field)> _
Public MustInherit Class ComparisonConstraint
Inherits Constraint

it has this constuctor:
Public Sub New(ByVal value As Object)
Me.value = value
End Sub

and the last one in the chain is :
<AttributeUsage(AttributeTargets.Property Or
AttributeTargets.Field)> _
Public MustInherit Class Constraint
Inherits Attribute
with the default constructor
The probelm as I can c, is that int is a premitive type
which can not be converted to object type because
attribute require a constant ... But this all structure
works in C# .... This is driving me crazy ... can you
suggest.

Thankx in advance.
-----Original Message-----
Hi zsilence,

|| Public Sub New(ByVal value As Object)
|| MyBase.New (value)
|| End Sub

This will work
Public Sub New (Value As Integer)

As to why there is a conversion error, I do not know.

I'm puzzled by your MyBase.New (value). What Attribute class are yourinheriting from ? The base class Attribute doesn't take parametres in itsNew().

You say it works in C#. Can you show me your Attribute class in C# and inVB?

Regards,
Fergus
.

Nov 20 '05 #3

P: n/a
>I have created my attribute with the constructor as
follows:

Public Sub New(ByVal value As Object)
MyBase.New(value)
End Sub


VB.NET and the CLS doesn't support Object attribute parmeters, so if
possible you should avoid using that.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.