public void CtorTest ()
		{
			AttributeProviderAttribute a;

			a = new AttributeProviderAttribute (typeof (string));
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, a.TypeName, "1");
			Assert.IsNull (a.PropertyName, "2");

			a = new AttributeProviderAttribute ("typename");
			Assert.AreEqual ("typename", a.TypeName, "3");
			Assert.AreEqual (null, a.PropertyName, "4");

			a = new AttributeProviderAttribute ("typename", "propertyname");
			Assert.AreEqual ("typename", a.TypeName, "5");
			Assert.AreEqual ("propertyname", a.PropertyName, "6");
		}
Esempio n. 2
0
        protected override void FillAttributes(IList attributes)
        {
            foreach (Attribute attribute in TypeDescriptor.GetAttributes(this.PropertyType))
            {
                attributes.Add(attribute);
            }
            BindingFlags bindingAttr    = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            Type         componentClass = this.componentClass;
            int          num            = 0;

            while ((componentClass != null) && (componentClass != typeof(object)))
            {
                num++;
                componentClass = componentClass.BaseType;
            }
            if (num > 0)
            {
                componentClass = this.componentClass;
                Attribute[][] attributeArray = new Attribute[num][];
                while ((componentClass != null) && (componentClass != typeof(object)))
                {
                    MemberInfo member = null;
                    if (this.IsExtender)
                    {
                        member = componentClass.GetMethod("Get" + this.Name, bindingAttr);
                    }
                    else
                    {
                        member = componentClass.GetProperty(this.Name, bindingAttr, null, this.PropertyType, new Type[0], new ParameterModifier[0]);
                    }
                    if (member != null)
                    {
                        attributeArray[--num] = ReflectTypeDescriptionProvider.ReflectGetAttributes(member);
                    }
                    componentClass = componentClass.BaseType;
                }
                foreach (Attribute[] attributeArray2 in attributeArray)
                {
                    if (attributeArray2 != null)
                    {
                        foreach (Attribute attribute2 in attributeArray2)
                        {
                            AttributeProviderAttribute attribute3 = attribute2 as AttributeProviderAttribute;
                            if (attribute3 != null)
                            {
                                Type type = Type.GetType(attribute3.TypeName);
                                if (type != null)
                                {
                                    Attribute[] attributeArray3 = null;
                                    if (!string.IsNullOrEmpty(attribute3.PropertyName))
                                    {
                                        MemberInfo[] infoArray = type.GetMember(attribute3.PropertyName);
                                        if ((infoArray.Length > 0) && (infoArray[0] != null))
                                        {
                                            attributeArray3 = ReflectTypeDescriptionProvider.ReflectGetAttributes(infoArray[0]);
                                        }
                                    }
                                    else
                                    {
                                        attributeArray3 = ReflectTypeDescriptionProvider.ReflectGetAttributes((MemberInfo)type);
                                    }
                                    if (attributeArray3 != null)
                                    {
                                        foreach (Attribute attribute4 in attributeArray3)
                                        {
                                            attributes.Add(attribute4);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                foreach (Attribute[] attributeArray4 in attributeArray)
                {
                    if (attributeArray4 != null)
                    {
                        foreach (Attribute attribute5 in attributeArray4)
                        {
                            attributes.Add(attribute5);
                        }
                    }
                }
            }
            base.FillAttributes(attributes);
            if (this.SetMethodValue == null)
            {
                attributes.Add(ReadOnlyAttribute.Yes);
            }
        }