예제 #1
0
        private static MapColumn[] CheckProperty(IDataReader reader, PropertyInfo[] Properties)
        {
            List <MapColumn> lst    = new List <MapColumn>(Properties.Length);
            List <string>    lstCol = new List <string>(reader.FieldCount);

            for (int i = 0; i < reader.FieldCount; i++)
            {
                lstCol.Add(reader.GetName(i));
            }
            foreach (var property in Properties)
            {
                string             colName   = property.Name;
                DataFieldAttribute aliasAttr = property.GetCustomAttribute <DataFieldAttribute>();
                if (aliasAttr != null)
                {
                    colName = aliasAttr.ColumnName;
                }
                if (lstCol.Contains(colName))
                {
                    MapColumn column = new MapColumn()
                    {
                        ColumnName = colName, Property = property
                    };
                    lst.Add(column);
                }
            }
            return(lst.ToArray());
        }
        /// <summary>
        /// 检查列
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="Properties"></param>
        /// <returns></returns>
        private static MapColumn[] CheckProperty(DataTable dt, PropertyInfo[] Properties)
        {
            List <MapColumn> lst = new List <MapColumn>(Properties.Length);

            foreach (var property in Properties)
            {
                string             colName   = property.Name;
                DataFieldAttribute aliasAttr = property.GetCustomAttribute <DataFieldAttribute>();
                if (aliasAttr != null)
                {
                    colName = aliasAttr.ColumnName;
                }
                if (dt.Columns.Contains(colName))
                {
                    MapColumn column = new MapColumn()
                    {
                        ColumnName = colName, Property = property
                    };
                    lst.Add(column);
                }
            }
            return(lst.ToArray());
        }