public static int ForPropertyDescriptor(PropertyDescriptor pd, double pxOnChar) { DefaultWidthAttribute attribute = (DefaultWidthAttribute)pd.Attributes[typeof(DefaultWidthAttribute)]; if (attribute == null) { return(ForType(pd.PropertyType, pxOnChar)); } MaxLengthAttribute attribute2 = (MaxLengthAttribute)pd.Attributes[typeof(MaxLengthAttribute)]; int num = (attribute2 != null) ? ((int)((attribute2.MaxLength * pxOnChar) * 1.1)) : 0x7fffffff; if (attribute.InChars) { return(Math.Min((int)((attribute.Width * pxOnChar) * 1.1), num)); } return(Math.Min(attribute.Width, num)); }
public static int ForType(Type type, double pxOnChar) { int width; DefaultWidthAttribute customAttribute = (DefaultWidthAttribute)Attribute.GetCustomAttribute(type, typeof(DefaultWidthAttribute)); if (customAttribute != null) { if (!customAttribute.InChars) { return(customAttribute.Width); } width = customAttribute.Width; } else { width = ForType(type); } return((int)((width * pxOnChar) * 1.1)); }
public static string ForPropertyDescriptor(PropertyDescriptor pd) { DefaultWidthAttribute attribute = (DefaultWidthAttribute)pd.Attributes[typeof(DefaultWidthAttribute)]; if (attribute == null) { return(ForTypeImpl(pd.PropertyType)); } if (!attribute.InChars) { return(attribute.Width + "px"); } int width = attribute.Width; MaxLengthAttribute attribute2 = (MaxLengthAttribute)pd.Attributes[typeof(MaxLengthAttribute)]; if ((attribute2 != null) && (attribute2.MaxLength < width)) { width = attribute2.MaxLength; } return(width.ToString()); }
private static string ForTypeImpl(Type type) { int width; DefaultWidthAttribute customAttribute = (DefaultWidthAttribute)Attribute.GetCustomAttribute(type, typeof(DefaultWidthAttribute)); if (customAttribute != null) { if (!customAttribute.InChars) { return(customAttribute.Width + "px"); } width = customAttribute.Width; } else { width = ForType(type); } if (width < 0) { return(null); } return(width.ToString()); }