コード例 #1
0
ファイル: DbHelper.cs プロジェクト: xisuo67/OracleDbHelper
        private static List <T> ToList <T>(OracleDataReader reader, TypeDescription description) where T : class, new()
        {
            Type type = typeof(T);

            Dictionary <string, DbMapInfo> dict = description.MemberDict;

            List <T> list = new List <T>();

            string[] names = GetColumnNames(reader);
            while (reader.Read())
            {
                T obj = Activator.CreateInstance(type) as T;
                for (int i = 0; i < names.Length; i++)
                {
                    string name = names[i];

                    DbMapInfo info;
                    if (dict.TryGetValue(name, out info))
                    {
                        object val = reader.GetValue(i);
                        if (val != null && DBNull.Value.Equals(val) == false && (info.AttrIgnore == null || info.AttrIgnore.SelectConvert))
                        {
                            if (info.AttrColumn != null && info.AttrColumn.TimeStamp)
                            {
                                info.PropertyInfo.FastSetValue(obj, val.ConvertToTimeStamp(info.PropertyInfo.PropertyType));
                            }
                            else
                            {
                                info.PropertyInfo.FastSetValue(obj, val.Convert(info.PropertyInfo.PropertyType));
                            }
                        }
                    }
                }
                list.Add(obj);
            }
            return(list);
        }
コード例 #2
0
ファイル: DbHelper.cs プロジェクト: xisuo67/OracleDbHelper
        internal static List <T> ToList <T>(DataTable table, TypeDescription description) where T : class, new()
        {
            Type type = typeof(T);

            Dictionary <string, DbMapInfo> dict = description.MemberDict;

            List <T> list = new List <T>();

            foreach (DataRow row in table.Rows)
            {
                T obj = Activator.CreateInstance(type) as T;
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    string    name = table.Columns[i].ColumnName;
                    DbMapInfo info;
                    if (dict.TryGetValue(name, out info))
                    {
                        object val = row[i];

                        if (val != null && DBNull.Value.Equals(val) == false && info.AttrIgnore == null)
                        {
                            if (info.AttrColumn != null && info.AttrColumn.TimeStamp)
                            {
                                info.PropertyInfo.FastSetValue(obj, val.ConvertToTimeStamp(info.PropertyInfo.PropertyType));
                            }
                            else
                            {
                                info.PropertyInfo.FastSetValue(obj, val.Convert(info.PropertyInfo.PropertyType));
                            }
                        }
                    }
                }
                list.Add(obj);
            }
            return(list);
        }
コード例 #3
0
 public static void SaveComplieResult(Type type, TypeDescription description)
 {
     s_typeInfoDict[type.FullName] = description;
 }