internal virtual object CreateUIEditor(PropertyModelView.OptionItemPropertyDescriptor desc) { OptionItem item = desc.Item; // EditorAttribute editorAttribute = // TypeDescriptor.GetProperties(item, false)["Value"].Attributes[typeof(EditorAttribute)] // as EditorAttribute; // UITypeEditor coreEditor; // if (editorAttribute.EditorTypeName != "") { // //attribute set, get the converter that is set by the attribute // coreEditor = TypeDescriptor.GetProperties(item, false)["Value"].GetEditor(); // } else { // //no attribute, delegate to base // coreEditor = TypeDescriptor.GetConverter(item.Type); // } object editor = TypeDescriptor.GetEditor(desc.PropertyType, typeof(UITypeEditor)); UITypeEditor _delegate = editor as UITypeEditor; object editorOverride = item.GetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR); if (editorOverride != null) { if (editorOverride is Type) { try { UITypeEditor o = System.Activator.CreateInstance((Type)editorOverride) as UITypeEditor; if (o != null) { _delegate = o; } } catch { Trace.WriteLine("Cannot create UI editor instance"); } } else if (editorOverride is string) { try { UITypeEditor o = System.Activator.CreateInstance(Type.GetType((string)editorOverride)) as UITypeEditor; if (o != null) { _delegate = o; } } catch { Trace.WriteLine("Cannot create UI editor instance"); } } else if (editorOverride is UITypeEditor) { _delegate = (UITypeEditor)editorOverride; } else { Trace.WriteLine("Invalid type for UI editor attribute"); } } // if(_delegate != null && _delegate is EnumUITypeEditor) { // IItemRenderer renderer = GetRenderer(item); // if(renderer != null) { // ((EnumUITypeEditor) _delegate).Renderer = renderer; // } // } bool supportNull = (bool)desc.Item.GetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE); bool supportUndef = (bool)desc.Item.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE); if (supportNull) { return(_delegate == null ? (supportUndef ? new UndefinedValueUITypeEditor() : editor) : new NullableUITypeEditor(_delegate)); } else { return(supportUndef ? new UndefinedValueUITypeEditor(_delegate) : _delegate); } }
internal virtual TypeConverter CreateConverter(PropertyModelView.OptionItemPropertyDescriptor desc, I18NFactory i18NFactory, string context) { OptionItem item = desc.Item; TypeConverterAttribute converterAttr = TypeDescriptor.GetProperties(item, false)["Value"].Attributes[typeof(TypeConverterAttribute)] as TypeConverterAttribute; TypeConverter coreConverter; if (desc is PropertyModelView.ListPropertyDescriptor && converterAttr.ConverterTypeName == "") { //special handling for the list converter coreConverter = new I18NTypeConverter(((PropertyModelView.ListPropertyDescriptor)desc).GetStringRepresentation(), (bool) item.GetAttribute( CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE)); } else if (item is ICollectionSupport && converterAttr.ConverterTypeName == "") { //special handling for the list converter coreConverter = new ListTypeConverter(((ICollectionSupport)item).Domain, ((ICollectionSupport)item).EntryType, (bool) item.GetAttribute( CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE), i18NFactory, desc.I18nKey, context); } else if (converterAttr.ConverterTypeName != "") { //attribute set, get the converter that is set by the attribute coreConverter = TypeDescriptor.GetProperties(item, false)["Value"].Converter; } else { //no attribute, delegate to base coreConverter = TypeDescriptor.GetConverter(item.Type); } //TypeConverter coreConverter = converterAttr.ConverterTypeName != "" ? itemConverter : base.Converter; //todo: make this dependent on item attribute bool supportNull = (bool)item.GetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE); bool supportUndefined = (bool)item.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE); string nullValueRepresentation = item.GetAttribute(OptionItem.NULL_VALUE_STRING_ATTRIBUTE) as string; if (i18NFactory != null) { nullValueRepresentation = PropertyModelView.GetLocalizedString( i18NFactory, context, desc.I18nKey + ".VALUE.", nullValueRepresentation); } //test for overrides object converterOverride = item.GetAttribute(OptionItem.CUSTOM_CONVERTER_ATTRIBUTE); if (converterOverride != null) { if (converterOverride is TypeConverter) { return((TypeConverter)converterOverride); } if (converterOverride is Type) { try { TypeConverter o = System.Activator.CreateInstance((Type)converterOverride) as TypeConverter; if (o != null) { coreConverter = o; } } catch { Trace.WriteLine("Cannot create converter instance"); } } else if (converterOverride is string) { try { TypeConverter o = System.Activator.CreateInstance(Type.GetType((string)converterOverride)) as TypeConverter; if (o != null) { coreConverter = o; } } catch { Trace.WriteLine("Cannot create converter instance"); } } else { Trace.WriteLine("Invalid type for converter attribute"); } } if (supportNull || supportUndefined) { //custom conversions needed... if (coreConverter is ExpandableObjectConverter || coreConverter is FontConverter || coreConverter is PointConverter ) { return(new ExpandableNullableTypeConverter(coreConverter, supportNull, supportUndefined, nullValueRepresentation == null ? "" : nullValueRepresentation)); } else { return(new NullableTypeConverter(coreConverter, supportNull, supportUndefined, nullValueRepresentation == null ? "" : nullValueRepresentation)); } } return(coreConverter); }