问题描述
我正在尝试实现ICustomTypeDescriptor,以便我可以按逻辑顺序显示类的属性,而不是按照字母顺序在PropertyGrid控件中显示。 在实现GetProperties方法时,我首先创建了一个新的PropertyDescriptorCollection。 然后我发现我无法为这个新集合添加属性,因为PropertyDescriptor的构造函数受到保护。
如果构造函数受到保护,如何创建PropertyDescriptor的实例?
这是我到目前为止所做的,显然不起作用:
PropertyDescriptor [] properties = new PropertyDescriptor [1];
属性[0] = new PropertyDescriptor ();
properties [0] .Category = "测试类别" ;
属性[0]。描述= "测试说明" ;
属性[0] .DisplayName = "测试属性" ;
属性[0] .Name = "TestProperty" ;
PropertyDescriptorCollection props = new PropertyDescriptorCollection (properties);
I am trying to implement ICustomTypeDescriptor so that I can display the properties of a class in a logical order rather than in alphabetical order in the PropertyGrid control. While implementing the GetProperties method, I started by creating a new PropertyDescriptorCollection. I then discovered that I cant add properties to this new collection because the constructor of PropertyDescriptor is protected.
How do I create instances of PropertyDescriptor's if the constructor is protected?
here is what i have so far, which obviously doesnt work:
PropertyDescriptor[] properties = new PropertyDescriptor[1];properties[0] = new PropertyDescriptor();
properties[0].Category = "test category";
properties[0].Description = "Test description";
properties[0].DisplayName = "Test Property";
properties[0].Name = "TestProperty";
PropertyDescriptorCollection props = new PropertyDescriptorCollection(properties);
这篇关于实现ICustomTypeDescriptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!