コード例 #1
1
ファイル: TypeDescriptor.cs プロジェクト: apakian/fluorinefx
        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);
                }
            }
		}
コード例 #2
0
ファイル: Namespace.cs プロジェクト: DarkActive/daFluorineFx
		public void AddTypeDescriptor(TypeDescriptor typeDescriptor)
		{
			TypeDescriptor[] tmpArray = new TypeDescriptor[_types.Length+1];
			if(_types.Length > 0)
				Array.Copy(_types, 0, tmpArray, 0, _types.Length);
			tmpArray[tmpArray.Length-1] = typeDescriptor;
			_types = tmpArray;
		}
コード例 #3
0
ファイル: Namespace.cs プロジェクト: DarkActive/daFluorineFx
 public bool Contains(TypeDescriptor typeDescriptor)
 {
     foreach (TypeDescriptor tmp in _types)
     {
         if (tmp.FullName == typeDescriptor.FullName)
             return true;
     }
     return false;
 }
コード例 #4
0
ファイル: TypeMapper.cs プロジェクト: apakian/fluorinefx
        public static ActionScriptType GetActionScriptType(TypeDescriptor typeDescriptor, Project project)
        {
            if (TypeMappingDictionary.Contains(typeDescriptor.FullName))
                return TypeMappingDictionary[typeDescriptor.FullName] as ActionScriptType;

            if (typeDescriptor.IsArray)
                return TypeMapper.Array;
            if (typeDescriptor.FullName == typeof(IList).FullName)
                return new ActionScriptType("mx.collections", "ArrayCollection", true);
            if (typeDescriptor.FullName.StartsWith("System.Collections.Generic.IList`1"))
                return new ActionScriptType("mx.collections", "ArrayCollection", true);
            if (typeDescriptor.FullName.StartsWith("System.Collections.Generic.ICollection`1"))
                return new ActionScriptType("mx.collections", "ArrayCollection", true);
            if (typeDescriptor.FullName.StartsWith(typeof(IDictionary).FullName))
                return TypeMapper.Object;
            if (typeDescriptor.Implements(typeof(IList).FullName))
            {
                //TODO: add legacy collection support
                return new ActionScriptType("mx.collections", "ArrayCollection", true);
            }
            //Generic IList
            if (typeDescriptor.Implements("System.Collections.Generic.IList`1"))
                return new ActionScriptType("mx.collections", "ArrayCollection", true);
            if (typeDescriptor.Implements("System.Collections.Generic.ICollection`1"))
                return new ActionScriptType("mx.collections", "ArrayCollection", true);
            if (typeDescriptor.Implements(typeof(IDictionary).FullName))
                return TypeMapper.Object;

            foreach (AssemblyDescriptor assemblyDescriptor in project.Assemblies)
            {
                foreach (TypeDescriptor typeDescriptorTmp in assemblyDescriptor.Types)
                {
                    if (typeDescriptor.FullName == typeDescriptorTmp.FullName)
                        return new ActionScriptType(typeDescriptor.Namespace, typeDescriptor.Name, false);
                }
            }
            return TypeMapper.Object;
        }
コード例 #5
0
        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();
		}
コード例 #6
0
ファイル: FieldDescriptor.cs プロジェクト: apakian/fluorinefx
        public FieldDescriptor(string name, TypeDescriptor typeDescriptor)
            : base(name)
		{
            _typeDescriptor = typeDescriptor;
        }
コード例 #7
0
        public PropertyDescriptor(string name, TypeDescriptor typeDescriptor)
            : base(name)
		{
            _typeDescriptor = typeDescriptor;
		}