您的位置:首页 > 其它

Class Design: 一些有用的Attribute

2010-09-14 16:34 330 查看
[Description("Dampingcalculationmethod"),CategoryAttribute("Generalpropellerdata")]
[TypeConverter(typeof(OptionConverter))]
[Range(0.0,1.0,ErrorMessage="PitchRatiomustbebetween0and1")]
[ReadOnly(false)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
publicdoublePitchRatio{get;set;}
[Range(1,5,ErrorMessage="PitchRatiomustbebetween1and5")][ReadOnly(false)][Browsable(false)][EditorBrowsable(EditorBrowsableState.Never)]
publicintPitchRatio{get;set;}
1)PropertyGridDataBinding支持/Array显示为Combox
[TypeConverter(typeof(OptionConverter))]
publicclassOptionConverter:StringConverter{publicstaticreadonlystring[]DampingModel={"Dynamicmagnifier","Schwanecke","Archer","Frahm"};publicoverrideTypeConverter.StandardValuesCollectionGetStandardValues(ITypeDescriptorContextcontext){returnnewStandardValuesCollection(DampingModel);}publicoverrideboolGetStandardValuesExclusive(ITypeDescriptorContextcontext){returntrue;//TruemakestheComboboxselectonly.Falseallowsfreetextentry.}publicoverrideboolGetStandardValuesSupported(ITypeDescriptorContextcontext){returntrue;//TruetellsthePropertyGridtodisplayaCombobox}}
2)Range
对于double,要用[Range(0.0,1.0,ErrorMessage="PitchRatiomustbebetween0.0and1.0")]
如果用[Range(0,1,ErrorMessage="PitchRatiomustbebetween0.0and1.0")],则失效。
类型的准确。
3)[Browsable(false)]
指定一个属性或事件是否应显示在“属性”窗口中。
4)[EditorBrowsable(EditorBrowsableState.Never)]
指定某个属性或方法在编辑器中可以查看.
例如,VisualStudio中的IntelliSense引擎使用此特性来确定是否显示属性或方法。
自己定义显示AutoCompletionList;
5)[ReadOnly(false)],Description("Dampingcalculationmethod"),CategoryAttribute("Generalpropellerdata")]

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: