public void Build(Type type, Hashtable typeDescriptorDictionary) { _attributeCollection.Clear(); _fullName = type.FullName; _name = type.Name; _isArray = type.IsArray; this.Namespace = type.Namespace; ArrayList interfaces = new ArrayList(); foreach (Type typeInterface in type.GetInterfaces()) { if (!typeDescriptorDictionary.Contains(typeInterface)) { TypeDescriptor typeDescriptorTmp = new TypeDescriptor(typeInterface); typeDescriptorDictionary.Add(typeInterface, typeDescriptorTmp); typeDescriptorTmp.Build(typeInterface, typeDescriptorDictionary); } TypeDescriptor typeDescriptor = typeDescriptorDictionary[typeInterface] as TypeDescriptor; interfaces.Add(typeDescriptor); } _interfaces = interfaces.ToArray(typeof(TypeDescriptor)) as TypeDescriptor[]; ArrayList methods = new ArrayList(); foreach(MethodInfo methodInfo in type.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly)) { if( SkipMethod(methodInfo) ) continue; MethodDescriptor methodDescriptor = new MethodDescriptor(); methodDescriptor.Build(methodInfo); methods.Add(methodDescriptor); } _methods = methods.ToArray(typeof(MethodDescriptor)) as MethodDescriptor[]; PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); ArrayList properties = new ArrayList(propertyInfos); int i = 0; for (i = properties.Count - 1; i >= 0; i--) { PropertyInfo propertyInfo = properties[i] as PropertyInfo; if (propertyInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0) properties.RemoveAt(i); if (propertyInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0) properties.RemoveAt(i); if (propertyInfo.GetGetMethod() == null || propertyInfo.GetGetMethod().GetParameters().Length > 0) properties.RemoveAt(i); } ArrayList tmp = new ArrayList(properties.Count); foreach (PropertyInfo propertyInfo in properties) { if (!typeDescriptorDictionary.Contains(propertyInfo.PropertyType)) { TypeDescriptor typeDescriptorTmp = new TypeDescriptor(propertyInfo.PropertyType); typeDescriptorDictionary.Add(propertyInfo.PropertyType, typeDescriptorTmp); typeDescriptorTmp.Build(propertyInfo.PropertyType, typeDescriptorDictionary); } TypeDescriptor typeDescriptor = typeDescriptorDictionary[propertyInfo.PropertyType] as TypeDescriptor; PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyInfo.Name, typeDescriptor); tmp.Add(propertyDescriptor); } _properties = tmp.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[]; FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); ArrayList fields = new ArrayList(fieldInfos); for (i = fields.Count - 1; i >= 0; i--) { FieldInfo fieldInfo = fields[i] as FieldInfo; if (fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0) fields.RemoveAt(i); if (fieldInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0) fields.RemoveAt(i); } tmp = new ArrayList(fields.Count); foreach (FieldInfo fieldInfo in fields) { if (!typeDescriptorDictionary.Contains(fieldInfo.FieldType)) { TypeDescriptor typeDescriptorTmp = new TypeDescriptor(fieldInfo.FieldType); typeDescriptorDictionary.Add(fieldInfo.FieldType, typeDescriptorTmp); typeDescriptorTmp.Build(fieldInfo.FieldType, typeDescriptorDictionary); } TypeDescriptor typeDescriptor = typeDescriptorDictionary[fieldInfo.FieldType] as TypeDescriptor; FieldDescriptor fieldDescriptor = new FieldDescriptor(fieldInfo.Name, typeDescriptor); tmp.Add(fieldDescriptor); } _fields = tmp.ToArray(typeof(FieldDescriptor)) as FieldDescriptor[]; object[] attrs = type.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); if( attrs.Length > 0 ) { System.ComponentModel.DescriptionAttribute descriptionAttribute = attrs[0] as System.ComponentModel.DescriptionAttribute; _description = descriptionAttribute.Description; } attrs = type.GetCustomAttributes(true); if (attrs != null && attrs.Length > 0) { for (i = 0; i < attrs.Length; i++) { Attribute attribute = attrs[i] as Attribute; if (attribute is System.ComponentModel.DescriptionAttribute) continue; AttributeDescriptor attributeDescriptor = new AttributeDescriptor(attribute.GetType().Name); if( !_attributeCollection.Contains(attributeDescriptor.Name) ) _attributeCollection.Add(attributeDescriptor); } } }
public void Build(Type type, Hashtable typeDescriptorDictionary) { _attributeCollection.Clear(); _fullName = type.FullName; _name = type.Name; _isArray = type.IsArray; this.Namespace = type.Namespace; ArrayList interfaces = new ArrayList(); foreach (Type typeInterface in type.GetInterfaces()) { if (!typeDescriptorDictionary.Contains(typeInterface)) { TypeDescriptor typeDescriptorTmp = new TypeDescriptor(typeInterface); typeDescriptorDictionary.Add(typeInterface, typeDescriptorTmp); typeDescriptorTmp.Build(typeInterface, typeDescriptorDictionary); } TypeDescriptor typeDescriptor = typeDescriptorDictionary[typeInterface] as TypeDescriptor; interfaces.Add(typeDescriptor); } _interfaces = interfaces.ToArray(typeof(TypeDescriptor)) as TypeDescriptor[]; ArrayList methods = new ArrayList(); foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { if (SkipMethod(methodInfo)) { continue; } MethodDescriptor methodDescriptor = new MethodDescriptor(); methodDescriptor.Build(methodInfo); methods.Add(methodDescriptor); } _methods = methods.ToArray(typeof(MethodDescriptor)) as MethodDescriptor[]; PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); ArrayList properties = new ArrayList(propertyInfos); int i = 0; for (i = properties.Count - 1; i >= 0; i--) { PropertyInfo propertyInfo = properties[i] as PropertyInfo; if (propertyInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0) { properties.RemoveAt(i); } if (propertyInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0) { properties.RemoveAt(i); } if (propertyInfo.GetGetMethod() == null || propertyInfo.GetGetMethod().GetParameters().Length > 0) { properties.RemoveAt(i); } } ArrayList tmp = new ArrayList(properties.Count); foreach (PropertyInfo propertyInfo in properties) { if (!typeDescriptorDictionary.Contains(propertyInfo.PropertyType)) { TypeDescriptor typeDescriptorTmp = new TypeDescriptor(propertyInfo.PropertyType); typeDescriptorDictionary.Add(propertyInfo.PropertyType, typeDescriptorTmp); typeDescriptorTmp.Build(propertyInfo.PropertyType, typeDescriptorDictionary); } TypeDescriptor typeDescriptor = typeDescriptorDictionary[propertyInfo.PropertyType] as TypeDescriptor; PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyInfo.Name, typeDescriptor); tmp.Add(propertyDescriptor); } _properties = tmp.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[]; FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); ArrayList fields = new ArrayList(fieldInfos); for (i = fields.Count - 1; i >= 0; i--) { FieldInfo fieldInfo = fields[i] as FieldInfo; if (fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0) { fields.RemoveAt(i); } if (fieldInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0) { fields.RemoveAt(i); } } tmp = new ArrayList(fields.Count); foreach (FieldInfo fieldInfo in fields) { if (!typeDescriptorDictionary.Contains(fieldInfo.FieldType)) { TypeDescriptor typeDescriptorTmp = new TypeDescriptor(fieldInfo.FieldType); typeDescriptorDictionary.Add(fieldInfo.FieldType, typeDescriptorTmp); typeDescriptorTmp.Build(fieldInfo.FieldType, typeDescriptorDictionary); } TypeDescriptor typeDescriptor = typeDescriptorDictionary[fieldInfo.FieldType] as TypeDescriptor; FieldDescriptor fieldDescriptor = new FieldDescriptor(fieldInfo.Name, typeDescriptor); tmp.Add(fieldDescriptor); } _fields = tmp.ToArray(typeof(FieldDescriptor)) as FieldDescriptor[]; object[] attrs = type.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); if (attrs.Length > 0) { System.ComponentModel.DescriptionAttribute descriptionAttribute = attrs[0] as System.ComponentModel.DescriptionAttribute; _description = descriptionAttribute.Description; } attrs = type.GetCustomAttributes(true); if (attrs != null && attrs.Length > 0) { for (i = 0; i < attrs.Length; i++) { Attribute attribute = attrs[i] as Attribute; if (attribute is System.ComponentModel.DescriptionAttribute) { continue; } AttributeDescriptor attributeDescriptor = new AttributeDescriptor(attribute.GetType().Name); if (!_attributeCollection.Contains(attributeDescriptor.Name)) { _attributeCollection.Add(attributeDescriptor); } } } }
public void Add(AttributeDescriptor value) { base.BaseAdd(value.Name, value); }
public void Add( string name, AttributeDescriptor value ) { base.BaseAdd(name, value); }
public void Add(AttributeDescriptor value) { base.BaseAdd(value.Name, value); }
public void Add(string name, AttributeDescriptor value) { base.BaseAdd(name, value); }