public EditorWindow(object action) { var configPropCollection = ConfigPropertyCollection.FromObject(action); InitializeComponent(); _PropertyGrid.SelectedObject = action; _PropertyGrid.Properties.Clear(); foreach (var configProp in configPropCollection) { var item = new PropertyItem(_PropertyGrid, action, configProp); _PropertyGrid.Properties.Add(item); } foreach (var category in _PropertyGrid.Categories) { category.Comparer = new PropertyOrderComparer(); } }
private void MatchProperties(ConfigPropertyCollection col) { Type colType = col.GetType(); MethodInfo indexer = colType.GetMethods().Single(x => x.Name == GET_ITEM && x.GetParameters().Any( p => p.Name.Equals(LOWER_NAME, StringComparison.CurrentCultureIgnoreCase) && p.ParameterType.Equals(typeof(string)))); IEnumerable <PropertyInfo> allProps = this.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public).Where( x => x.CanWrite && (CustomAttributeData.GetCustomAttributes(x).Count == 0 || !CustomAttributeData.GetCustomAttributes(x).Select(a => a.AttributeType).Any( t => t.Equals(typeof(ObsoleteAttribute))))); foreach (PropertyInfo pi in allProps) { object val = null; try { val = indexer.Invoke(col, new object[1] { pi.Name }); } catch (TargetInvocationException) { } if (val != null && val is ConfigProperty cp) { if (pi.PropertyType.Equals(typeof(bool?))) { bool yesno = Convert.ToBoolean(cp.RunValue); pi.SetValue(this, yesno); } else if (pi.PropertyType.Equals(typeof(BinaryChoice?))) { pi.SetValue(this, (BinaryChoice)cp.RunValue); } else { pi.SetValue(this, cp.RunValue); } } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var collection = ConfigPropertyCollection.FromObject(value); return(collection.Count > 0 ? Visibility.Visible : Visibility.Collapsed); }