Beispiel #1
0
        /// <summary>
        /// 检查可匹配的列
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="Properties"></param>
        /// <returns></returns>
        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());
        }
Beispiel #2
0
        /// <summary>
        /// 检查列;获取DataTable有列的属性集合
        /// </summary>
        /// <param name="dt">DataTable</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;
                NoColumnAttribute noColumn = property.GetCustomAttribute <NoColumnAttribute>();
                if (noColumn != null)
                {
                    continue;
                }
                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());
        }