コード例 #1
0
        internal SPFieldAttribute Clone(SPFieldProvisionMode provisionMode)
        {
            SPFieldAttribute value = this.Clone();

            if (provisionMode > value.ProvisionMode)
            {
                value.ProvisionMode = provisionMode;
            }
            return(value);
        }
コード例 #2
0
        private static IEnumerable <SPFieldAttribute> EnumerateFieldAttributes(SPModelDescriptor descriptor, Type sourceType, Type implementedType)
        {
            InterfaceMapping mapping = default(InterfaceMapping);

            if (sourceType.IsInterface)
            {
                mapping = implementedType.GetInterfaceMap(sourceType);
            }
            foreach (MemberInfo member in sourceType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                SPModelFieldAssociationCollection collection      = QueryableFields.EnsureKeyValue(member);
                SPModelFieldAssociationCollection otherCollection = null;
                if (sourceType.IsInterface)
                {
                    MethodInfo lookupMethod = null;
                    if (member.MemberType == MemberTypes.Property)
                    {
                        lookupMethod = ((PropertyInfo)member).GetGetMethod() ?? ((PropertyInfo)member).GetSetMethod();
                    }
                    else if (member.MemberType == MemberTypes.Method)
                    {
                        lookupMethod = (MethodInfo)member;
                    }
                    if (lookupMethod != null)
                    {
                        int pos = Array.IndexOf(mapping.InterfaceMethods, lookupMethod);
                        if (pos >= 0)
                        {
                            MemberInfo mappedMember = mapping.TargetMethods[pos];
                            if (member.MemberType == MemberTypes.Property)
                            {
                                mappedMember = implementedType.GetProperty(mappedMember.Name.Substring(4));
                            }
                            if (mappedMember != null)
                            {
                                otherCollection = QueryableFields.EnsureKeyValue(mappedMember);
                                if (otherCollection.Count > 0)
                                {
                                    foreach (SPModelFieldAssociation value in otherCollection)
                                    {
                                        collection.Add(value);
                                    }
                                }
                            }
                        }
                    }
                }

                SPFieldProvisionMode provisionMode = SPFieldProvisionMode.Default;
                SPModelFieldAssociationCollection basePropertyCollection = null;
                IEnumerable <SPFieldAttribute>    attributes             = member.GetCustomAttributes <SPFieldAttribute>(true);

                if (member.MemberType == MemberTypes.Property)
                {
                    PropertyInfo baseProperty = ((PropertyInfo)member).GetBaseDefinition();
                    if (baseProperty != member)
                    {
                        if (!attributes.Any())
                        {
                            attributes    = baseProperty.GetCustomAttributes <SPFieldAttribute>(false);
                            provisionMode = SPFieldProvisionMode.None;
                        }
                        else
                        {
                            basePropertyCollection = QueryableFields.EnsureKeyValue(baseProperty);
                            provisionMode          = SPFieldProvisionMode.FieldLink;
                        }
                    }
                }
                if (member.DeclaringType != sourceType)
                {
                    provisionMode = SPFieldProvisionMode.FieldLink;
                }
                foreach (SPFieldAttribute attribute in attributes)
                {
                    if (attribute.IncludeInQuery)
                    {
                        PropertyInfo property = null;
                        SPModelQueryPropertyAttribute queryPropertyAttribute = member.GetCustomAttribute <SPModelQueryPropertyAttribute>(false);
                        if (queryPropertyAttribute != null)
                        {
                            property = queryPropertyAttribute.QueryProperty;
                        }
                        SPModelFieldAssociation value = new SPModelFieldAssociation(descriptor, attribute, property);
                        collection.Add(value);
                        if (otherCollection != null)
                        {
                            otherCollection.Add(value);
                        }
                        if (basePropertyCollection != null)
                        {
                            basePropertyCollection.Add(value);
                        }
                        if (property != null)
                        {
                            SPModelFieldAssociationCollection foreignPropertyCollection = QueryableFields.EnsureKeyValue(property);
                            foreignPropertyCollection.Add(new SPModelFieldAssociation(descriptor, attribute, null));
                        }
                    }
                    yield return(attribute.Clone(provisionMode));
                }
            }
        }