attribute syntax error

R

raulavi

having this attribute (see bottom)

HOW CAN i specify attribute [MyCustomAttr("clssA"),IncludeOnBrowse =
true] for the FileName property....
as it is I get systanx error at compile.

-----------------------------------------------------------------
using system;
public class Class1
{

private string _FileName;
[Size(SizeAttribute.Unlimited)]
[MyCustomAttr("clssA"),IncludeOnBrowse = true]
public string FileName
{
get { return _FileName; }
set
{
_FileName = value;
}
}
}

-----------------------------------------------------------------
-----------------------------------------------------------------

public class MyCustomAttrAttribute : System.Attribute
{
private string name;
public MyCustomAttrAttribute(string n)
{
this.name = n;
}
}
private bool includeOnBrowse;
public bool IncludeOnBrowse
{
get { return this.includeOnBrowse; }
set {this.includeOnBrowse = value;}
}
}

-----------------------
 
J

Jeff Johnson

HOW CAN i specify attribute [MyCustomAttr("clssA"),IncludeOnBrowse
=
true] for the FileName property....

You can only set properties via the constructor, so you would have to call
it like this:

[MyCustomAttr("clssA", IncludeOnBrowse = true)]

and change the constructor to accept two arguments.
 
J

Josh Einstein

No that's not true. The attribute syntax you showed is correct, but
IncludeOnBrowse has to remain a property in order to set it by name.

Josh Einstein
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top