C# to Java: What is a [DefaultProperty("value")]?
I do not understand how the DefaultProperty Metadata tag work or what it signifies. I've read the MSDN and went through the sample but I find it confusing.
DefaultPropertyAttribute Class
I've read a few blogs and they seem to refer to the indexers. I'm not sure why you would want metadata for your properties? I am coming from a Java background, perhaps a Java analogy would help.
[DefaultProperty("Value")]
开发者_如何转开发 public abstract class FOO<T> : ANY, IBAR<T>
{
public FOO() { }
public FOO(T value) { this.Value = value; }
public virtual T Value { get; set; }
}
Follow up: Property Grid
This is used for property grids.
When you select a component in the designer, it looks for a DefaultProperty
attribute and selects that property by default.
You can safely ignore it.
The DefaultEvent
attribute is similar.
Attributes are metadata, like the Java annotations. They're not used by the class to which they are applied, but by other classes, or the IDE designer for example.
精彩评论