/// <summary> /// Compares this object to another <see cref="DesignLineStyle"/>. /// </summary> public int CompareTo(DesignTextStyle other) { int delta = this.Family == null ? -1 : this.Family.CompareTo(other.Family); if (delta == 0) { delta = this.Size == null ? -1 : this.Size.CompareTo(other.Size); } if (delta == 0) { delta = this.Style == null ? -1 : this.Style.CompareTo(other.Style); } if (delta == 0) { delta = this.Weight == null ? -1 : this.Weight.CompareTo(other.Weight); } if (delta == 0) { delta = this.Decoration == null ? -1 : this.Decoration.CompareTo(other.Decoration); } if (delta == 0) { delta = this.Color == null ? -1 : this.Color.CompareTo(other.Color); } return(delta); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) { if (!(value is DesignTextStyle)) { return(string.Empty); } DesignTextStyle textStyle = (DesignTextStyle)value; if (textStyle.IsNullable) { return(string.Empty); } if (culture == null) { culture = CultureInfo.CurrentUICulture; } StringExpressionInfoConverter stringConverter = new StringExpressionInfoConverter(); ColorExpressionInfoConverter colorConverter = new ColorExpressionInfoConverter(); LengthExpressionInfoConverter lengthConverter = new LengthExpressionInfoConverter(); EnumExpressionInfoConverter enumConverter = new EnumExpressionInfoConverter(); string separator = culture.TextInfo.ListSeparator + " "; StringBuilder sb = new StringBuilder(); sb.Append(stringConverter.ConvertTo(context, culture, textStyle.Family, destinationType)); sb.Append(separator); sb.Append(lengthConverter.ConvertTo(context, culture, textStyle.Size, destinationType)); sb.Append(separator); sb.Append(enumConverter.ConvertTo(context, culture, textStyle.Style, destinationType)); sb.Append(separator); sb.Append(enumConverter.ConvertTo(context, culture, textStyle.Weight, destinationType)); sb.Append(separator); sb.Append(enumConverter.ConvertTo(context, culture, textStyle.Decoration, destinationType)); sb.Append(separator); sb.Append(colorConverter.ConvertTo(context, culture, textStyle.Color, destinationType)); return(sb.ToString()); } return(base.ConvertTo(context, culture, value, destinationType)); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { DesignTextStyle lineStyle = (DesignTextStyle)value; const int N = 6; PropertyDescriptor[] properties = new PropertyDescriptor[N]; properties[0] = new ShadowProperty(FontFamilyDisplayName, TypeDescriptor.CreateProperty( typeof(DesignTextStyle), FontFamilyPropertyName, typeof(ExpressionInfo), new TypeConverterAttribute(lineStyle.IsNullable ? typeof(NullableFontFamilyExpressionInfoConverter) : typeof(FontFamilyExpressionInfoConverter)) )); properties[1] = new ShadowProperty(FontSizeDisplayName, TypeDescriptor.CreateProperty( typeof(DesignTextStyle), FontSizePropertyName, typeof(ExpressionInfo), new TypeConverterAttribute(lineStyle.IsNullable ? typeof(NullableLengthExpressionInfoConverter) : typeof(LengthExpressionInfoConverter)) )); properties[2] = new ShadowProperty(FontStyleDisplayName, TypeDescriptor.CreateProperty( typeof(DesignTextStyle), FontStylePropertyName, typeof(ExpressionInfo), new TypeConverterAttribute(lineStyle.IsNullable ? typeof(NullableEnumExpressionInfoConverter) : typeof(EnumExpressionInfoConverter)) )); properties[3] = new ShadowProperty(FontWeightDisplayName, TypeDescriptor.CreateProperty( typeof(DesignTextStyle), FontWeightPropertyName, typeof(ExpressionInfo), new TypeConverterAttribute(lineStyle.IsNullable ? typeof(NullableEnumExpressionInfoConverter) : typeof(EnumExpressionInfoConverter)) )); properties[4] = new ShadowProperty(FontDecorationDisplayName, TypeDescriptor.CreateProperty( typeof(DesignTextStyle), FontDecorationPropertyName, typeof(ExpressionInfo), new TypeConverterAttribute(lineStyle.IsNullable ? typeof(NullableEnumExpressionInfoConverter) : typeof(EnumExpressionInfoConverter)) )); properties[5] = new ShadowProperty(FontColorDisplayName, TypeDescriptor.CreateProperty( typeof(DesignTextStyle), FontColorPropertyName, typeof(ExpressionInfo), new TypeConverterAttribute(lineStyle.IsNullable ? typeof(NullableColorExpressionInfoConverter) : typeof(ColorExpressionInfoConverter)) )); PropertyDescriptorCollection pdc = new PropertyDescriptorCollection(properties); return(pdc.Sort(PropertySortOrder)); }