当前位置: 代码迷 >> .NET分析设计 >> 写了个Record类,求一上
  详细解决方案

写了个Record类,求一上

热度:6490   发布时间:2013-02-25 00:00:00.0
写了个Record类,求高手指点一下!

public class Record<T>
        where T:class
    {
        private System.Collections.Generic.Dictionary<string, object> m_Record = null;

        private static readonly System.Collections.Generic.Dictionary<Entities.RecordMapping,System.Reflection.PropertyInfo> PatternRecordMappingList;

        static Record()
        {
            Record<T>.PatternRecordMappingList = new Dictionary<RecordMapping, System.Reflection.PropertyInfo>();
            Type PatternType = typeof(T);
            System.Reflection.PropertyInfo[] PatternTypeProperties = PatternType.GetProperties();
            foreach (var Item in PatternTypeProperties)
            {
                object[] Result = Item.GetCustomAttributes(true);
                foreach (var Mapping in Result)
                {
                    if (Mapping.GetType() == typeof(Entities.RecordMapping))
                        Record<T>.PatternRecordMappingList.Add(Mapping as Entities.RecordMapping,Item);
                }
            }
        }

        public Record(System.Data.IDataReader Reader)
        {
            this.Initialize(Reader);
        }

        protected void Initialize(System.Data.IDataReader Reader)
        {
            object c = Reader[0];
            this.m_Record = new Dictionary<string, object>(Reader.FieldCount);
            for (int Index = 0; Index < Reader.FieldCount; Index++)
            {
                this.m_Record.Add(Reader.GetName(Index), Reader[Index]);
            }
        }

        public T Entity()
        {
            Type EntityType = typeof(T);
  相关解决方案