private static void MergeMappingItems(ORMappingItemCollection dest, ORMappingItemCollection src)
 {
     foreach (ORMappingItem item in src)
     {
         if (dest.Contains(item.DataFieldName) == false)
         {
             dest.Add(item);
         }
     }
 }
        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.Contains(attr.DataFieldName) == false)
                    {
                        ORMappingItem item = new ORMappingItem();

                        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);
                    }
                }
            }

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

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

            return(items);
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="row">DataRow对象</param>
        /// <param name="items">映射关系</param>
        /// <param name="graph">对象</param>
        /// <param name="dod"></param>
        public static void DataRowToObject <T>(DataRow row, ORMappingItemCollection items, T graph, DataToObjectDeligations dod)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(row != null, "row");
            ExceptionHelper.FalseThrow <ArgumentNullException>(items != null, "items");
            ExceptionHelper.FalseThrow <ArgumentNullException>(graph != null, "graph");
            ExceptionHelper.FalseThrow <ArgumentNullException>(row.Table != null, "row.Table");

            foreach (DataColumn column in row.Table.Columns)
            {
                if (items.Contains(column.ColumnName))
                {
                    ORMappingItem item = items[column.ColumnName];

                    System.Type realType = GetRealType(item.MemberInfo);

                    object data = row[column];
                    if (Convertible(realType, data))
                    {
                        SetValueToObject(item, graph, ConvertData(item, data), row, dod);
                    }
                }
            }
        }
        /// <summary>
        /// 将DataReader的值写入到对象中
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="dr">IDataReader对象</param>
        /// <param name="items">映射关系</param>
        /// <param name="graph">对象</param>
        /// <param name="dod"></param>
        public static void DataReaderToObject <T>(IDataReader dr, ORMappingItemCollection items, T graph, DataToObjectDeligations dod)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(dr != null, "dr");
            ExceptionHelper.FalseThrow <ArgumentNullException>(items != null, "items");
            ExceptionHelper.FalseThrow <ArgumentNullException>(graph != null, "graph");

            DataTable schemaTable = dr.GetSchemaTable();

            foreach (DataRow row in schemaTable.Rows)
            {
                string columnName = row["ColumnName"].ToString();
                if (items.Contains(columnName))
                {
                    ORMappingItem item     = items[row["ColumnName"].ToString()];
                    System.Type   realType = GetRealType(item.MemberInfo);

                    object data = dr[columnName];
                    if (Convertible(realType, data))
                    {
                        SetValueToObject(item, graph, ConvertData(item, data), dr, dod);
                    }
                }
            }
        }