public PropertyEditor CreateEditor(Type baseType, ProviderContext context)
			{
				PropertyEditor e = null;

				// Basic numeric data types
				if (baseType == typeof(sbyte) || baseType == typeof(byte) ||
					baseType == typeof(short) || baseType == typeof(ushort) ||
					baseType == typeof(int) || baseType == typeof(uint) ||
					baseType == typeof(long) || baseType == typeof(ulong) ||
					baseType == typeof(float) || baseType == typeof(double) || baseType == typeof(decimal))
					e = new NumericPropertyEditor();
				// Basic data type: Boolean
				else if (baseType == typeof(bool))
				    e = new BoolPropertyEditor();
				// Basic data type: Flagged Enum
				else if (baseType.IsEnum && baseType.GetCustomAttributes(typeof(FlagsAttribute), true).Any())
					e = new FlaggedEnumPropertyEditor();
				// Basic data type: Other Enums
				else if (baseType.IsEnum)
					e = new EnumPropertyEditor();
				// Basic data type: String
				else if (baseType == typeof(string))
					e = new StringPropertyEditor();
				// IList
				else if (typeof(System.Collections.IList).IsAssignableFrom(baseType))
					e = new IListPropertyEditor();
				// IList
				else if (typeof(System.Collections.IDictionary).IsAssignableFrom(baseType))
					e = new IDictionaryPropertyEditor();
				// Unknown data type
				else
				{
					// Ask around if any sub-editor can handle it and choose the most specialized
					var availSubProviders = 
						from p in this.subProviders
						where p.IsResponsibleFor(baseType, context) != EditorPriority_None
						orderby p.IsResponsibleFor(baseType, context) descending
						select p;
					IPropertyEditorProvider subProvider = availSubProviders.FirstOrDefault();
					if (subProvider != null)
					{
						e = subProvider.CreateEditor(baseType, context);
						e.EditedType = baseType;
						return e;
					}

					// If not, default to reflection-driven MemberwisePropertyEditor
					e = new MemberwisePropertyEditor();
				}

				e.EditedType = baseType;
				return e;
			}
示例#2
0
            public PropertyEditor CreateEditor(Type baseType, ProviderContext context)
            {
                PropertyEditor e = null;

                // Basic numeric data types
                if (baseType == typeof(sbyte) || baseType == typeof(byte) ||
                    baseType == typeof(short) || baseType == typeof(ushort) ||
                    baseType == typeof(int) || baseType == typeof(uint) ||
                    baseType == typeof(long) || baseType == typeof(ulong) ||
                    baseType == typeof(float) || baseType == typeof(double) || baseType == typeof(decimal))
                {
                    e = new NumericPropertyEditor();
                }
                // Basic data type: Boolean
                else if (baseType == typeof(bool))
                {
                    e = new BoolPropertyEditor();
                }
                // Basic data type: Flagged Enum
                else if (baseType.IsEnum && baseType.GetCustomAttributes(typeof(FlagsAttribute), true).Any())
                {
                    e = new FlaggedEnumPropertyEditor();
                }
                // Basic data type: Other Enums
                else if (baseType.IsEnum)
                {
                    e = new EnumPropertyEditor();
                }
                // Basic data type: String
                else if (baseType == typeof(string))
                {
                    e = new StringPropertyEditor();
                }
                // IList
                else if (typeof(System.Collections.IList).IsAssignableFrom(baseType))
                {
                    e = new IListPropertyEditor();
                }
                // IList
                else if (typeof(System.Collections.IDictionary).IsAssignableFrom(baseType))
                {
                    e = new IDictionaryPropertyEditor();
                }
                // Unknown data type
                else
                {
                    // Ask around if any sub-editor can handle it and choose the most specialized
                    var availSubProviders =
                        from p in this.subProviders
                        where p.IsResponsibleFor(baseType, context) != EditorPriority_None
                        orderby p.IsResponsibleFor(baseType, context) descending
                        select p;

                    IPropertyEditorProvider subProvider = availSubProviders.FirstOrDefault();
                    if (subProvider != null)
                    {
                        e            = subProvider.CreateEditor(baseType, context);
                        e.EditedType = baseType;
                        return(e);
                    }

                    // If not, default to reflection-driven MemberwisePropertyEditor
                    e = new MemberwisePropertyEditor();
                }

                e.EditedType = baseType;
                return(e);
            }