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); } } }
internal void Build(Assembly assembly, bool isWebServiceProxy, Type[] excludedTypes, Type[] attributes, Hashtable typeDescriptorDictionary) { _isWebServiceProxy = isWebServiceProxy; _fullName = assembly.FullName; _name = assembly.GetName().Name; Hashtable excludeTypesDictionary = new Hashtable(); foreach (Type type in excludedTypes) { excludeTypesDictionary.Add(type, null); } ArrayList types = new ArrayList(); try { foreach (Type type in assembly.GetTypes()) { if (excludeTypesDictionary.ContainsKey(type)) { continue; } if (type.BaseType != null && excludeTypesDictionary.ContainsKey(type.BaseType)) { continue; } //do not check accesibility with TypeHelper as the input custom attributes will filter //if( !TypeHelper.GetTypeIsAccessible(type) ) // continue; //do not reflect servicebrowser classes if (type.FullName.StartsWith("FluorineFx.") && !type.FullName.StartsWith(FluorineFx.Configuration.FluorineConfiguration.Instance.FluorineSettings.WsdlProxyNamespace)) { continue; } bool match = attributes != null && attributes.Length > 0 ? false : true; foreach (Type attributeType in attributes) { object[] attrs = type.GetCustomAttributes(attributeType, true); if (attrs != null && attrs.Length > 0) { match = true; break; } } if (match) { TypeDescriptor typeDescriptor = new TypeDescriptor(); typeDescriptor.Build(type, typeDescriptorDictionary); types.Add(typeDescriptor); } } } catch (Exception ex) { log.Warn(string.Format("Error building assembly descriptor {0}", assembly.FullName), ex); } _types = types.ToArray(typeof(TypeDescriptor)) as TypeDescriptor[]; BuildNamespaceHierarchy(); }
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); } } } }
internal void Build(Assembly assembly, bool isWebServiceProxy, Type[] excludedTypes, Type[] attributes, Hashtable typeDescriptorDictionary) { _isWebServiceProxy = isWebServiceProxy; _fullName = assembly.FullName; _name = assembly.GetName().Name; Hashtable excludeTypesDictionary = new Hashtable(); foreach(Type type in excludedTypes) excludeTypesDictionary.Add(type, null); ArrayList types = new ArrayList(); try { foreach (Type type in assembly.GetTypes()) { if (excludeTypesDictionary.ContainsKey(type)) continue; if (type.BaseType != null && excludeTypesDictionary.ContainsKey(type.BaseType)) continue; //do not check accesibility with TypeHelper as the input custom attributes will filter //if( !TypeHelper.GetTypeIsAccessible(type) ) // continue; //do not reflect servicebrowser classes if (type.FullName.StartsWith("FluorineFx.") && !type.FullName.StartsWith(FluorineFx.Configuration.FluorineConfiguration.Instance.FluorineSettings.WsdlProxyNamespace)) continue; bool match = attributes != null && attributes.Length > 0 ? false : true; foreach (Type attributeType in attributes) { object[] attrs = type.GetCustomAttributes(attributeType, true); if (attrs != null && attrs.Length > 0) { match = true; break; } } if (match) { TypeDescriptor typeDescriptor = new TypeDescriptor(); typeDescriptor.Build(type, typeDescriptorDictionary); types.Add(typeDescriptor); } } } catch (Exception ex) { log.Warn(string.Format("Error building assembly descriptor {0}", assembly.FullName), ex); } _types = types.ToArray(typeof(TypeDescriptor)) as TypeDescriptor[]; BuildNamespaceHierarchy(); }