Пример #1
0
        private static T ReadObject <T>(IObjectReader <T> reader, DbDataReader dbReader)
        {
            // Retrieve an existin item or create a new one
            T obj = default(T);

            if (reader.RecordInstance != null) // Use an existing instance if any
            {
                obj = (T)reader.RecordInstance;
            }
            else if (reader.TypeMap != null)
            {
                obj = (T)reader.TypeMap.CreateObject(dbReader);
            }
            else
            {
                obj = (T)typeof(T).CreateInstance();
            }

            reader.ReadRecord(dbReader, obj); // Populate the item from the reader

            return(obj);
        }