Example #1
0
        private static ConditionMappingItemCollection GetMappingItemsBySubClass(RelativeAttributes attrs, MemberInfo sourceMI)
        {
            ConditionMappingItemCollection items = new ConditionMappingItemCollection();

            System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

            MemberInfo[] mis = GetTypeMembers(subType);

            foreach (SubConditionMappingAttribute attr in attrs.SubClassFieldMappings)
            {
                MemberInfo mi = GetMemberInfoByName(attr.SubPropertyName, mis);

                if (mi != null)
                {
                    ConditionMappingItem item = new ConditionMappingItem();

                    item.PropertyName         = sourceMI.Name;
                    item.SubClassPropertyName = attr.SubPropertyName;
                    item.MemberInfo           = mi;

                    if (attrs.SubClassType != null)
                    {
                        item.SubClassTypeDescription = attrs.SubClassType.TypeDescription;
                    }

                    FillMappingItemByAttr(item, attr);

                    items.Add(item);
                }
            }

            return(items);
        }
        private static ORMappingItemCollection GetMappingItems(RelativeAttributes attrs, MemberInfo mi)
        {
            ORMappingItemCollection items = new ORMappingItemCollection();

            ORMappingItem item = new ORMappingItem();

            item.PropertyName  = mi.Name;
            item.DataFieldName = mi.Name;

            if (attrs.FieldMapping != null)
            {
                FillMappingItemByAttr(item, attrs.FieldMapping);
            }

            if (attrs.SqlBehavior != null)
            {
                FillMappingItemByBehaviorAttr(item, attrs.SqlBehavior);
            }

            item.MemberInfo = mi;

            items.Add(item);

            return(items);
        }
Example #3
0
        private static RelativeAttributes GetRelativeAttributes(MemberInfo mi)
        {
            RelativeAttributes result = new RelativeAttributes();

            Attribute[] attrs = Attribute.GetCustomAttributes(mi, true);

            foreach (Attribute attr in attrs)
            {
                if (attr is NoMappingAttribute)
                {
                    result.NoMapping = (NoMappingAttribute)attr;
                    break;
                }
                else
                if (attr is SubConditionMappingAttribute)
                {
                    result.SubClassFieldMappings.Add((SubConditionMappingAttribute)attr);
                }
                else
                if (attr is SubClassTypeAttribute)
                {
                    result.SubClassType = (SubClassTypeAttribute)attr;
                }
                else
                if (attr is ConditionMappingAttribute)
                {
                    result.FieldMapping = (ConditionMappingAttribute)attr;
                }
            }

            return(result);
        }
        private static XmlObjectMappingItemCollection GetMappingItemsBySubClass(RelativeAttributes attrs, MemberInfo sourceMI)
        {
            XmlObjectMappingItemCollection items = new XmlObjectMappingItemCollection();

            System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

            MemberInfo[] mis = GetTypeMembers(subType);

            foreach (XmlObjectSubClassMappingAttribute attr in attrs.SubClassFieldMappings)
            {
                MemberInfo mi = GetMemberInfoByName(attr.SubPropertyName, mis);

                if (mi != null)
                {
                    if (items.Contains(attr.NodeName) == false)
                    {
                        XmlObjectMappingItem item = new XmlObjectMappingItem(attr);

                        item.PropertyName         = sourceMI.Name;
                        item.SubClassPropertyName = attr.SubPropertyName;
                        item.MemberInfo           = mi;

                        if (attrs.SubClassType != null)
                        {
                            item.SubClassTypeDescription = attrs.SubClassType.TypeDescription;
                        }

                        items.Add(item);
                    }
                }
            }

            return(items);
        }
Example #5
0
        /// <summary>
        /// 得到属性路径中最低级别的MemberInfo
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="attrs"></param>
        /// <param name="sourceMI"></param>
        /// <returns></returns>
        private static MemberInfo GetLeaveMemberInfo(string propertyName, RelativeAttributes attrs, MemberInfo sourceMI)
        {
            MemberInfo result = null;

            string[] propertyParts = propertyName.Split('.');

            for (int i = 0; i < propertyParts.Length; i++)
            {
                System.Type subType = null;

                if (i == propertyParts.Length - 1)
                {
                    subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);
                }
                else
                {
                    subType = GetRealType(sourceMI);
                }

                MemberInfo[] mis = GetTypeMembers(subType);

                sourceMI = GetMemberInfoByName(propertyParts[i], mis);

                if (sourceMI == null)
                {
                    break;
                }
            }

            result = sourceMI;

            return(result);
        }
        internal static MemberInfo GetSubClassMemberInfoByName(string subClassPropertyName, MemberInfo sourceMI)
        {
            RelativeAttributes attrs = GetRelativeAttributes(sourceMI);

            System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

            return(GetSubClassMemberInfoByName(subClassPropertyName, subType));
        }
Example #7
0
        private static RelativeAttributes GetRelativeAttributes(MemberInfo mi)
        {
            RelativeAttributes result = new RelativeAttributes();

            Attribute[] attrs = Attribute.GetCustomAttributes(mi, true);

            foreach (Attribute attr in attrs)
            {
                if (attr is NoMappingAttribute)
                {
                    result.NoMapping = (NoMappingAttribute)attr;
                    break;
                }
                else
                {
                    if (attr is SubClassORFieldMappingAttribute)
                    {
                        result.SubClassFieldMappings.Add((SubClassORFieldMappingAttribute)attr);
                    }
                    else
                    {
                        if (attr is SubClassSqlBehaviorAttribute)
                        {
                            result.SubClassFieldSqlBehaviors.Add((SubClassSqlBehaviorAttribute)attr);
                        }
                        else
                        {
                            if (attr is SubClassTypeAttribute)
                            {
                                result.SubClassType = (SubClassTypeAttribute)attr;
                            }
                            else
                            if (attr is ORFieldMappingAttribute)
                            {
                                result.FieldMapping = (ORFieldMappingAttribute)attr;
                            }
                            else
                            if (attr is SqlBehaviorAttribute)
                            {
                                result.SqlBehavior = (SqlBehaviorAttribute)attr;
                            }
                            else
                            if (attr is SubClassPropertyEncryptionAttribute)
                            {
                                result.SubClassPropertyEncryptions.Add((SubClassPropertyEncryptionAttribute)attr);
                            }
                            else
                            if (attr is PropertyEncryptionAttribute)
                            {
                                result.PropertyEncryption = (PropertyEncryptionAttribute)attr;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #8
0
        private static ORMappingItemCollection GetMappingItemsBySubClass(RelativeAttributes attrs, MemberInfo sourceMI)
        {
            ORMappingItemCollection items = new ORMappingItemCollection();

            System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

            MemberInfo[] mis = GetTypeMembers(subType);

            foreach (SubClassORFieldMappingAttribute attr in attrs.SubClassFieldMappings)
            {
                MemberInfo mi = GetMemberInfoByName(attr.SubPropertyName, mis);

                if (mi != null)
                {
                    if (items.ContainsKey(attr.DataFieldName) == false)
                    {
                        ORMappingItem item = new ORMappingItem();

                        item.PropertyName         = sourceMI.Name;
                        item.SubClassPropertyName = attr.SubPropertyName;
                        item.MemberInfo           = mi;
                        item.DeclaringType        = sourceMI.DeclaringType;

                        if (attrs.SubClassType != null)
                        {
                            item.SubClassTypeDescription = attrs.SubClassType.TypeDescription;
                        }

                        FillMappingItemByAttr(item, attr);

                        items.Add(item);
                    }
                }
            }

            foreach (SubClassSqlBehaviorAttribute attr in attrs.SubClassFieldSqlBehaviors)
            {
                ORMappingItem item = FindItemBySubClassPropertyName(attr.SubPropertyName, items);

                if (item != null)
                {
                    FillMappingItemByBehaviorAttr(item, attr);
                }
            }

            foreach (SubClassPropertyEncryptionAttribute attr in attrs.SubClassPropertyEncryptions)
            {
                ORMappingItem item = FindItemBySubClassPropertyName(attr.SubPropertyName, items);

                if (item != null)
                {
                    FillMappingItemByEncryptionAttr(item, attr);
                }
            }

            return(items);
        }
        private static XmlObjectMappingItemCollection CreateMappingItems(MemberInfo mi, bool onlyMapMarkedProperties)
        {
            XmlObjectMappingItemCollection result = null;
            bool isDoMapping = false;

            RelativeAttributes attrs = null;

            if (mi.Name != "Item")
            {
                attrs = GetRelativeAttributes(mi);

                if (onlyMapMarkedProperties)
                {
                    isDoMapping = attrs.FieldMapping != null;
                }
                else
                {
                    isDoMapping = true;
                }

                if (isDoMapping && attrs.NoMapping == null)
                {
                    isDoMapping = true;
                }
                else
                {
                    isDoMapping = false;
                }
            }

            if (isDoMapping == true)
            {
                if (attrs != null)
                {
                    if (attrs.SubClassFieldMappings.Count > 0)
                    {
                        result = GetMappingItemsBySubClass(attrs, mi);
                    }
                    else
                    {
                        result = GetMappingItems(attrs, mi);
                    }
                }
            }
            else
            {
                result = new XmlObjectMappingItemCollection();
            }

            return(result);
        }
        private static XmlObjectMappingItemCollection GetMappingItems(RelativeAttributes attrs, MemberInfo mi)
        {
            XmlObjectMappingItemCollection items = new XmlObjectMappingItemCollection();

            XmlObjectMappingItem item = new XmlObjectMappingItem(attrs.FieldMapping);

            item.PropertyName = mi.Name;
            if (string.IsNullOrEmpty(item.NodeName))
            {
                item.NodeName = mi.Name;
            }

            item.MemberInfo = mi;

            items.Add(item);

            return(items);
        }
Example #11
0
        private static ConditionMappingItemCollection GetMappingItems(RelativeAttributes attrs, MemberInfo mi)
        {
            ConditionMappingItemCollection items = new ConditionMappingItemCollection();

            ConditionMappingItemBase item = CreateConditionMappingItemByAttr(attrs.FieldMapping);

            item.PropertyName  = mi.Name;
            item.DataFieldName = mi.Name;

            if (attrs.FieldMapping != null)
            {
                item.FillFromAttr(attrs.FieldMapping);
            }

            item.MemberInfo = mi;

            items.Add(item);

            return(items);
        }
Example #12
0
        private static ORMappingItemCollection CreateMappingItems(MemberInfo mi)
        {
            ORMappingItemCollection result = null;
            bool isDoMapping = false;

            RelativeAttributes attrs = null;

            Type realType = GetRealType(mi);

            //不处理除byte[]之外的集合类
            if (mi.Name != "Item" && (realType == typeof(byte[]) || realType.GetInterface("ICollection") == null))
            {
                attrs = GetRelativeAttributes(mi);

                if (attrs.NoMapping == null)
                {
                    isDoMapping = true;
                }
            }

            if (isDoMapping == true)
            {
                if (attrs != null)
                {
                    if (attrs.SubClassFieldMappings.Count > 0 || attrs.SubClassFieldSqlBehaviors.Count > 0)
                    {
                        result = GetMappingItemsBySubClass(attrs, mi);
                    }
                    else
                    {
                        result = GetMappingItems(attrs, mi);
                    }
                }
            }
            else
            {
                result = new ORMappingItemCollection();
            }

            return(result);
        }
        private static ORMappingItemCollection CreateMappingItems(MemberInfo mi)
        {
            ORMappingItemCollection result = null;
            bool isDoMapping = false;

            RelativeAttributes attrs = null;

            if (mi.Name != "Item" &&
                (GetRealType(mi).GetInterface("ICollection") == null ||
                 GetRealType(mi).Name.ToLower() == "byte[]")) //byte[] 对应sql的image类型
            {
                attrs = GetRelativeAttributes(mi);

                if (attrs.NoMapping == null)
                {
                    isDoMapping = true;
                }
            }

            if (isDoMapping == true)
            {
                if (attrs != null)
                {
                    if (attrs.SubClassFieldMappings.Count > 0 || attrs.SubClassFieldSqlBehaviors.Count > 0)
                    {
                        result = GetMappingItemsBySubClass(attrs, mi);
                    }
                    else
                    {
                        result = GetMappingItems(attrs, mi);
                    }
                }
            }
            else
            {
                result = new ORMappingItemCollection();
            }

            return(result);
        }
Example #14
0
        private static ConditionMappingItemCollection CreateMappingItems(MemberInfo mi)
        {
            ConditionMappingItemCollection result = null;
            bool isDoMapping = false;

            RelativeAttributes attrs = null;

            //if (mi.Name != "Item" && GetRealType(mi).GetInterface("ICollection") == null)
            if (mi.Name != "Item")
            {
                attrs = GetRelativeAttributes(mi);

                if (attrs.NoMapping == null)
                {
                    isDoMapping = true;
                }
            }

            if (isDoMapping == true)
            {
                if (attrs != null)
                {
                    if (attrs.SubClassFieldMappings.Count > 0)
                    {
                        result = GetMappingItemsBySubClass(attrs, mi);
                    }
                    else
                    {
                        result = GetMappingItems(attrs, mi);
                    }
                }
            }
            else
            {
                result = new ConditionMappingItemCollection();
            }

            return(result);
        }
		private static RelativeAttributes GetRelativeAttributes(MemberInfo mi)
		{
			RelativeAttributes result = new RelativeAttributes();

			Attribute[] attrs = Attribute.GetCustomAttributes(mi, true);

			foreach (Attribute attr in attrs)
			{
				if (attr is NoMappingAttribute)
				{
					result.NoMapping = (NoMappingAttribute)attr;
					break;
				}
				else
					if (attr is SubConditionMappingAttribute)
						result.SubClassFieldMappings.Add((SubConditionMappingAttribute)attr);
					else
						if (attr is SubClassTypeAttribute)
							result.SubClassType = (SubClassTypeAttribute)attr;
						else
							if (attr is ConditionMappingAttribute)
								result.FieldMapping = (ConditionMappingAttribute)attr;
			}

			return result;
		}
		private static ConditionMappingItemCollection GetMappingItems(RelativeAttributes attrs, MemberInfo mi)
		{
			ConditionMappingItemCollection items = new ConditionMappingItemCollection();

			ConditionMappingItem item = new ConditionMappingItem();
			item.PropertyName = mi.Name;
			item.DataFieldName = mi.Name;

			if (attrs.FieldMapping != null)
				FillMappingItemByAttr(item, attrs.FieldMapping);

			item.MemberInfo = mi;

			items.Add(item);

			return items;
		}
		private static ConditionMappingItemCollection GetMappingItemsBySubClass(RelativeAttributes attrs, MemberInfo sourceMI)
		{
			ConditionMappingItemCollection items = new ConditionMappingItemCollection();
			System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

			MemberInfo[] mis = GetTypeMembers(subType);

			foreach (SubConditionMappingAttribute attr in attrs.SubClassFieldMappings)
			{
				MemberInfo mi = GetMemberInfoByName(attr.SubPropertyName, mis);

				if (mi != null)
				{
					ConditionMappingItem item = new ConditionMappingItem();

					item.PropertyName = sourceMI.Name;
					item.SubClassPropertyName = attr.SubPropertyName;
					item.MemberInfo = mi;

					if (attrs.SubClassType != null)
						item.SubClassTypeDescription = attrs.SubClassType.TypeDescription;

					FillMappingItemByAttr(item, attr);

					items.Add(item);
				}
			}

			return items;
		}