Attributes and constant expressions

  • Thread starter Thread starter Matthias Steinbart
  • Start date Start date
M

Matthias Steinbart

Hi there,

I'm creating a class to be viewed in a property-grid control. I'm using the
Browsable, Category, Description, etc. -Attributes to specify the
display-behaviour of the class in the prop-grid Control. My problem is, I'd
like to load the values for the DescriptionAttributes from a string
resource, but the compiler keeps telling me, I have to use constant values
for the Attributes. How can this be solved?

Thanks in advance,

Matthias
 
Matthias,

If you want to do this, then you will have to implement
ICustomTypeDescriptor on your class, and implement the GetAttributes method
so that it returns the instance of the Description attribute with the
appropriate description.

The way that the framework does it is that it uses an attribute called
SRDescription which appears to take an identifier for a resource, and pulls
the description from there. Unfortunately, that is an internal class, so
you can't apply it to your own controls.

Hope this helps.
 
Thanks Nicholas,

that helped.

Matthias

Nicholas Paldino said:
Matthias,

If you want to do this, then you will have to implement
ICustomTypeDescriptor on your class, and implement the GetAttributes method
so that it returns the instance of the Description attribute with the
appropriate description.

The way that the framework does it is that it uses an attribute called
SRDescription which appears to take an identifier for a resource, and pulls
the description from there. Unfortunately, that is an internal class, so
you can't apply it to your own controls.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Matthias Steinbart said:
Hi there,

I'm creating a class to be viewed in a property-grid control. I'm using the
Browsable, Category, Description, etc. -Attributes to specify the
display-behaviour of the class in the prop-grid Control. My problem is, I'd
like to load the values for the DescriptionAttributes from a string
resource, but the compiler keeps telling me, I have to use constant values
for the Attributes. How can this be solved?

Thanks in advance,

Matthias
 
Back
Top