/// <summary>
        /// Creates a new instance of the given editorType. It is assumed that editorType extends
        /// IPropertyEditor.
        /// </summary>
        private static bool TryCreateInstance(Type editorType, Type usedEditedType,
                                              Type actualEditedType, ICustomAttributeProvider attributes, out IPropertyEditor editor)
        {
            if (editorType.GetConstructor(fsPortableReflection.EmptyTypes) == null &&
                editorType.GetConstructor(NonEmptyConstructorArgs) == null)
            {
                Debug.LogWarning("Type " + editorType + " can serve as a property editor if it " +
                                 "has a default constructor or a constructor that takes a Type and an ICustomAttributeProvider arguments");
                editor = null;
                return(false);
            }

            if (CanEdit(usedEditedType,
                        fsPortableReflection.GetAttribute <CustomPropertyEditorAttribute>(editorType)) == false)
            {
                editor = null;
                return(false);
            }

            try {
                if (editorType.GetConstructor(NonEmptyConstructorArgs) != null)
                {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType, new object[] { actualEditedType, attributes });
                }
                else
                {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType);
                }
            }
            catch (Exception e) {
                Debug.LogException(e);
                editor = null;
                return(false);
            }

            if (editor.CanEdit(actualEditedType) == false)
            {
                editor = null;
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
 private static bool TryCreateInstance(Type editorType, Type usedEditedType, Type actualEditedType, out IPropertyEditor editor)
 {
     if (editorType.GetConstructor(Type.EmptyTypes) == null)
     {
         Debug.LogWarning("Type " + editorType + " can serve as a property editor if it has a default constructor");
         editor = null;
         return false;
     }
     editor = (IPropertyEditor)Activator.CreateInstance(editorType);
     if (!PropertyEditorTools.CanEdit(usedEditedType, editorType.GetAttribute<CustomPropertyEditorAttribute>()))
     {
         editor = null;
         return false;
     }
     if (!editor.CanEdit(actualEditedType))
     {
         editor = null;
         return false;
     }
     return true;
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance of the given editorType. It is assumed that editorType extends
        /// IPropertyEditor.
        /// </summary>
        private static bool TryCreateInstance(Type editorType, Type usedEditedType,
            Type actualEditedType, ICustomAttributeProvider attributes, out IPropertyEditor editor) {

            if (editorType.GetConstructor(fsPortableReflection.EmptyTypes) == null &&
                editorType.GetConstructor(NonEmptyConstructorArgs) == null) {

                Debug.LogWarning("Type " + editorType + " can serve as a property editor if it " +
                    "has a default constructor or a constructor that takes a Type and an ICustomAttributeProvider arguments");
                editor = null;
                return false;
            }

            if (CanEdit(usedEditedType,
                fsPortableReflection.GetAttribute<CustomPropertyEditorAttribute>(editorType)) == false) {
                editor = null;
                return false;
            }

            try {
                if (editorType.GetConstructor(NonEmptyConstructorArgs) != null) {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType, new object[] { actualEditedType, attributes });
                }
                else {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType);
                }
            }
            catch (Exception e) {
                Debug.LogException(e);
                editor = null;
                return false;
            }

            if (editor.CanEdit(actualEditedType) == false) {
                editor = null;
                return false;
            }

            return true;
        }