void AddTypeDescriptors() { var dtd = DynamicTypeDescriptor.Install(typeof(OxyColor)); dtd.SetConverter(new OxyColorConverter()); TypeDescriptor.Refresh(typeof(OxyColor)); }
static SeriesTypeConverter() { // Find all the series types var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetExportedTypes() .Where(t => t.IsSubclassOf(typeof(Series)) && !t.IsAbstract)) .Where(t => t != typeof(FunctionSeries)) .ToArray(); // Hide all the properties we're not interested in foreach (var type in types) { var dtd = DynamicTypeDescriptor.Install(type); foreach (var prop in dtd.GetProperties()) { var dprop = (DynamicPropertyDescriptor)prop; if (dprop.IsReadOnly || dprop.PropertyType.IsSubclassOf(typeof(Delegate)) || dprop.PropertyType == typeof(object) || dprop.Name == "Parent" || dprop.Name.EndsWith("Field")) { dprop.SetIsBrowsable(false); } } } // Create the name mapping map = types.ToDictionary(ToString, t => (Series)Activator.CreateInstance(t)); names = types.Select(ToString).ToArray(); }
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { if (instance != null) { ICustomTypeDescriptor perInstance; perInstanceMap.TryGetValue(instance, out perInstance); if (perInstance != null) { return(perInstance); } } DynamicTypeDescriptor ret; if (!map.TryGetValue(objectType, out ret)) { map.Add(objectType, ret = new DynamicTypeDescriptor(objectType, parentProvider.GetTypeDescriptor(objectType))); } return(ret); }