Property's Description and Category do not work

  • Thread starter Thread starter David N
  • Start date Start date
D

David N

All,

I created a control that have the following property defined:

private bool autoSearch
[
DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")
]


My control is compiled and created fine. But, after adding the control to
my form, I noticed the following problems:

1. The autoSearch property does not show up in the Behavior category.
Instead, it's shown in the Misc. category.
2. The Decription does not show up at all. I can see the autoSearch
property. I can change its value from true to false. But when I clicked on
the autoSearch, its desciption does not show up.

Can someone shed a light on this?

Thanks.
 
Hi David,
You should specify attributes before the names they apply to:
[ DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")]
private bool autoSearch

HTH
B\rgds
100
 
100 said:
Hi David,
You should specify attributes before the names they apply to:
[ DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")]
private bool autoSearch

HTH
B\rgds
100




David N said:
All,

I created a control that have the following property defined:

private bool autoSearch
[
DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")
]


My control is compiled and created fine. But, after adding the control to
my form, I noticed the following problems:

1. The autoSearch property does not show up in the Behavior category.
Instead, it's shown in the Misc. category.
2. The Decription does not show up at all. I can see the autoSearch
property. I can change its value from true to false. But when I
clicked
on
the autoSearch, its desciption does not show up.

Can someone shed a light on this?

Thanks.
 
Sorry for all blank replies. My machine was out of memory and when I press
enter key, some how the message dialog was closed and the message was
sent....

Anh thank you for your reply. I swapped the attributes on top of the
property, but the result is the same. Beside, I don't think the position
makes the different, because I have another property of type string, and the
default value of each property was shown correctly...

100 said:
Hi David,
You should specify attributes before the names they apply to:
[ DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")]
private bool autoSearch

HTH
B\rgds
100




David N said:
All,

I created a control that have the following property defined:

private bool autoSearch
[
DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")
]


My control is compiled and created fine. But, after adding the control to
my form, I noticed the following problems:

1. The autoSearch property does not show up in the Behavior category.
Instead, it's shown in the Misc. category.
2. The Decription does not show up at all. I can see the autoSearch
property. I can change its value from true to false. But when I
clicked
on
the autoSearch, its desciption does not show up.

Can someone shed a light on this?

Thanks.
 
My fault!
The attribute declaration does have to be before the property {get/set}
pair. I have to close the solution and reopen it in order to see the
change.

Thanks a lot.
 
Hi David,
I'm glad that you managed to solve your problem. I just want to point you on
the fact that the position of the attribute declaration *does* matter.
Attributes are applied on the declaration that follows the place where the
attribute is specified. If there is ambiguity or your intent is different
than what is the default target an "atribute target specifier" can be used.

So in your example
private bool autoSearch
[
DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")
]

The attributes will be applied to what follows.

And if your code looks like this:

private bool autoSearch
[
DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")
]


public bool Foo()
{
......
}

The attribute is going to be applied to Foo method rather than autoSearch
member.

The attribute declaration does have to be before the property {get/set}
pair.
I don't realy understand what *before {get/set} pair* means.
If you have:

bool Prop
[SomeAttribute]
{
get{}
set{}
}

It is a syntax error and this won't compile.
----------------------------------------
[SomeAttribute]
bool Prop
{
get{}
set{}
}

You apply the attribute to the property.
-----------------------------------------
bool Prop
{

[SomeAttribute]
get{}
set{}
}

I this case by default the attribute will be applied to the *get* method.
You can apply the attribute to the returning value using *return* target
specifier. Anyway, the property Prop itself won't have attribute applied.
-------------------------------------------
bool Prop
{
get{}

[SomeAttribute]
set{}
}
By default you apply the atribute to the *set* method. You can apply the
attribute to the *value* parameter via specifying *param* target. As in the
previous case the property itself won't have attribute applied.

So the position of the attributes *does* matter.

B\rgds
100


David N said:
All,

I created a control that have the following property defined:

private bool autoSearch
[
DefaultValue(typeof(bool),true),
Description("Auto search upon typing"),
Category("Behavior")
]


My control is compiled and created fine. But, after adding the control to
my form, I noticed the following problems:

1. The autoSearch property does not show up in the Behavior category.
Instead, it's shown in the Misc. category.
2. The Decription does not show up at all. I can see the autoSearch
property. I can change its value from true to false. But when I
clicked
on
the autoSearch, its desciption does not show up.

Can someone shed a light on this?

Thanks.
 
Back
Top