LookupEnum() public static method

public static LookupEnum ( string typeName ) : Stetic.EnumDescriptor
typeName string
return Stetic.EnumDescriptor
Ejemplo n.º 1
0
        public TypedPropertyDescriptor(XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base(elem, group, klass)
        {
            this.klass = klass;
            string propertyName = elem.GetAttribute("name");
            int    dot          = propertyName.IndexOf('.');

            if (dot != -1)
            {
                // Sub-property (eg, "Alignment.Value")
                memberInfo        = FindProperty(klass.WrapperType, klass.WrappedType, propertyName.Substring(0, dot));
                isWrapperProperty = memberInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper));
                gladeProperty     = new TypedPropertyDescriptor(isWrapperProperty ? klass.WrapperType : klass.WrappedType, memberInfo.Name);
                propertyInfo      = FindProperty(memberInfo.PropertyType, propertyName.Substring(dot + 1));
            }
            else
            {
                // Basic simple property
                propertyInfo      = FindProperty(klass.WrapperType, klass.WrappedType, propertyName);
                isWrapperProperty = propertyInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper));
            }

            // Wrapper properties that override widgets properties (using the same name)
            // must be considered runtime properties (will be available at run-time).
            if (!isWrapperProperty || klass.WrappedType.GetProperty(propertyName) != null)
            {
                isRuntimeProperty = true;
            }

            if (!IsInternal && propertyInfo.PropertyType.IsEnum &&
                Registry.LookupEnum(propertyInfo.PropertyType.FullName) == null)
            {
                throw new ArgumentException("No EnumDescriptor for " + propertyInfo.PropertyType.FullName + "(" + klass.WrappedType.FullName + "." + propertyName + ")");
            }

            pspec = FindPSpec(propertyInfo);

            if (isWrapperProperty && pspec == null)
            {
                PropertyInfo pinfo = klass.WrappedType.GetProperty(propertyInfo.Name, flags);
                if (pinfo != null)
                {
                    pspec = FindPSpec(pinfo);
                }
            }

            if (pspec != null)
            {
                // This information will be overridden by what's specified in the xml file
                description = pspec.Blurb;
                minimum     = pspec.Minimum;
                maximum     = pspec.Maximum;
                label       = propertyName;
                if (!elem.HasAttribute("ignore-default"))
                {
                    hasDefault = Type.GetTypeCode(PropertyType) != TypeCode.Object || PropertyType.IsEnum;
                }
            }
            else
            {
                label         = propertyInfo.Name;
                gladeOverride = true;
            }

            string typeName = elem.GetAttribute("editor");

            if (typeName.Length > 0)
            {
                editorType = Registry.GetType(typeName, false);
            }

            // Look for a default value attribute

            object[] ats = propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true);
            if (ats.Length > 0)
            {
                DefaultValueAttribute at = (DefaultValueAttribute)ats [0];
                defaultValue = at.Value;
            }

            // Load default data
            Load(elem);
        }