DesignTimePropertyAttributes GetDesignTimePropertyAttributes(PropertyInfo propertyInfo) { DesignTimePropertyAttributes result = new DesignTimePropertyAttributes(); PrecisionAttribute numDigitsAttribute = propertyInfo.GetCustomAttribute <PrecisionAttribute>(); if (numDigitsAttribute != null) { result.NumDigits = numDigitsAttribute.NumDecimalPlaces; } DisplayTextAttribute displayTextAttribute = propertyInfo.GetCustomAttribute <DisplayTextAttribute>(); if (displayTextAttribute != null) { result.DisplayText = displayTextAttribute.DisplayText; } DependentPropertyAttribute dependentPropertyAttribute = propertyInfo.GetCustomAttribute <DependentPropertyAttribute>(); if (dependentPropertyAttribute != null) { result.DependentProperty = dependentPropertyAttribute.DependentProperty; } return(result); }
/// <summary> /// 验证精度(小数点数) /// </summary> /// <param name="box">验证框</param> /// <param name="min">最小精度</param> /// <param name="max">最大精度</param> /// <param name="errorMessage">提示信息</param> /// <returns></returns> public static ValidBox Precision(this ValidBox box, int min, int max, string errorMessage) { var newBox = new PrecisionAttribute(min, max) { ErrorMessage = errorMessage }.ToValidBox(); return(ValidBox.Merge(box, newBox)); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { var baseProperties = base.GetProperties(context, value, attributes); var precisionAttribute = new PrecisionAttribute(0, 1); var editorAttribute = new EditorAttribute(DesignTypes.SliderEditor, DesignTypes.UITypeEditor); var hueAttributes = new Attribute[] { new RangeAttribute(0, 179), precisionAttribute, editorAttribute }; var satValAttributes = new Attribute[] { new RangeAttribute(0, 255), precisionAttribute, editorAttribute }; var properties = new PropertyDescriptor[3]; properties[0] = new PropertyDescriptorWrapper("H", baseProperties["Val0"], hueAttributes); properties[1] = new PropertyDescriptorWrapper("S", baseProperties["Val1"], satValAttributes); properties[2] = new PropertyDescriptorWrapper("V", baseProperties["Val2"], satValAttributes); return(new PropertyDescriptorCollection(properties)); }
/// <summary> /// 验证精度(小数点数) /// </summary> /// <param name="box">验证框</param> /// <param name="min">最小精度</param> /// <param name="max">最大精度</param> /// <returns></returns> public static ValidBox Precision(this ValidBox box, int min, int max) { var newBox = new PrecisionAttribute(min, max).ToValidBox(); return(ValidBox.Merge(box, newBox)); }