/// <summary> /// Constructor that instantiates and sets up ProfessionalColorTable object</summary> public CustomColorTable() { var allPropInfos = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var properyMap = new Dictionary<string, PropertyInfo>(); int count = "Settable".Length; foreach (var propInfo in allPropInfos) { if (propInfo.PropertyType != typeof(Color)) continue; if (propInfo.Name.StartsWith("Settable")) { string name = propInfo.Name.Remove(0, count); properyMap.Add(name, propInfo); } } ProfessionalColorTable colorTable = new ProfessionalColorTable(); PropertyInfo[] originals = colorTable.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (var propInfo in originals) { PropertyInfo settable; if (properyMap.TryGetValue(propInfo.Name, out settable)) { settable.SetValue(this, propInfo.GetValue(colorTable, null), null); } } SettableToolStripBorder = Color.Transparent; SettableImageMarginGradientBegin = Color.Transparent; SettableImageMarginGradientMiddle = Color.Transparent; SettableImageMarginGradientEnd = Color.Transparent; }
public void InitFrom(ProfessionalColorTable colorTable, bool makeColorsDefault) { // Instead of "colors[ColorTableGroup.ButtonSelectedBorder] = colorTable.ButtonSelectedBorder"... // use reflection. Type colorTableType = colorTable.GetType(); Type colorTableGroupType = typeof(ColorTableGroup); foreach (ColorTableGroup colorTableGroup in Enum.GetValues(colorTableGroupType)) { var prop = colorTableType.GetProperty(Enum.GetName(colorTableGroupType, colorTableGroup)); if (prop != null) colors[colorTableGroup] = (Color)prop.GetValue(colorTable, null); } if (makeColorsDefault) MakeColorsDefault(); }