开发者

C# to Java: What is a [DefaultProperty("value")]?

开发者 https://www.devze.com 2022-12-26 20:22 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号