Ejemplo n.º 1
0
        /// ¹¹Ô캯Êý
        public XDataReader(IDataReader dataReader)
        {
            string       typeName     = dataReader.GetSchemaTable().TableName;
            DynamicClass dynamicClass = new DynamicClass(typeName);

            for (int i = 0; i < dataReader.FieldCount; i++)
            {
                string fieldType = dataReader.GetFieldType(i).Name;
                string name      = dataReader.GetName(i);

                dynamicClass.AddProperty(fieldType, name);
                this.columnNames.Add(name);
            }

            dynamicClass.CreateAssembly();

            while (dataReader.Read())
            {
                //object[] itemArray = new object[this.columnNames.Count];
                object entity = dynamicClass.CreateInstance();

                for (int i = 0; i < this.columnNames.Count; i++)
                {
                    object value = dataReader.GetValue(i);
                    DynamicClass.SetValue(entity, columnNames[i], value);
                }

                this.rows.Add(entity);
            }
        }