Пример #1
0
        private MetaType(Type type)
        {
            this._type = type;
            this._isComplex = TypeUtility.IsComplexType(type);

            // enumerate all properties and initialize property level info
            List<PropertyDescriptor> includedAssociations = new List<PropertyDescriptor>();
            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(type))
            {
                MetaMember metaMember = new MetaMember(this, pd);

                if (pd.Attributes[typeof(ExcludeAttribute)] == null)
                {
                    bool isPredefinedType = TypeUtility.IsPredefinedType(pd.PropertyType);
                    metaMember.IsCollection = TypeUtility.IsSupportedCollectionType(pd.PropertyType);
                    bool isComplex = TypeUtility.IsSupportedComplexType(pd.PropertyType);
                    metaMember.IsDataMember = isPredefinedType || isComplex;
                    metaMember.IsComplex = isComplex;
                    metaMember.RequiresValidation = pd.Attributes.OfType<ValidationAttribute>().Any();
                }
                
                if (pd.Attributes[typeof(AssociationAttribute)] != null)
                {
                    if (pd.Attributes.OfType<IncludeAttribute>().Any(p => !p.IsProjection))
                    {
                        includedAssociations.Add(pd);
                    }
                    metaMember.IsAssociationMember = true;
                }

                IncludeAttribute[] memberProjections = pd.Attributes.OfType<IncludeAttribute>().Where(p => p.IsProjection).ToArray();
                if (memberProjections.Length > 0)
                {
                    this._projectionMemberMap[pd] = memberProjections;
                }

                if (pd.Attributes[typeof(CompositionAttribute)] != null)
                {
                    this._hasComposition = true;
                }
                this._metaMembers.Add(pd.Name, metaMember);
            }

            this._includedAssociations = new PropertyDescriptorCollection(includedAssociations.ToArray(), true);

            this.CalculateAttributesRecursive(type, new HashSet<Type>());
        }