Custom Attribute and it influencing all my controls.  
Author Message
PureCode





PostPosted: Visual C# Language, Custom Attribute and it influencing all my controls. Top

Hi,

I have a custom attribute in my library (OnOffAttribute, to turn off or on a property) and it's behaving a little oddly.

Basically, all my controls use common classes for their drawing and such. I do not always need certain properties in these common classes, so i created an attribute (which is is used through ICustomTypeDescriptor and a custom TypeDescriptor) to do this based on (very vague) information found on the web.

The thing is, that if i set, for example, my "DisplayBorder" property to be 'off', it is off for ALL controls that use the common border class instead of just the control i set it to be off for. The border class is always instantiated in each control using the 'new' command and as thus i figured it'd be off only for the control that sets it to off, not ALL controls on my form.


Visual C#16  
 
 
PureCode





PostPosted: Visual C# Language, Custom Attribute and it influencing all my controls. Top

Hi again,

Forgot to show my DisableProperty method which is used to turn off or on a property.

 
 
micvos





PostPosted: Visual C# Language, Custom Attribute and it influencing all my controls. Top

Attributes are for storing metadata on classes, not for storing extra data on instances of a class. If you set the attribute on the common border class it will apply to all instances. What you need to do is to define an attribute that you can set on the classes that use the common border class. Than every class type can have a different value of that attribute.

 
 
PureCode





PostPosted: Visual C# Language, Custom Attribute and it influencing all my controls. Top

I was afraid of having to do that :)

Basically means that custom attributes for this sort of stuff are rather pointless (to me anyway), it's stupid to begin with that IsReadOnly is get only to begin with (*looks in MS' direction*).

Well, thanks Micvos.. i'll have another play with this stuff.

Regards,

Pure