 
                    
                
         
    
    
    
	
	
		
		
![]() using System;
using System;
![]() using System.Data;
using System.Data;
![]() using System.Configuration;
using System.Configuration;
![]() using System.Collections;
using System.Collections;
![]() using System.Web;
using System.Web;
![]() using System.Web.Security;
using System.Web.Security;
![]() using System.Web.UI;
using System.Web.UI;
![]() using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
![]() using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls.WebParts;
![]() using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;
![]() using System.Reflection;
using System.Reflection;
![]() using Microsoft.ApplicationBlocks.Data;
using Microsoft.ApplicationBlocks.Data;
![]() using System.Data.SqlClient;
using System.Data.SqlClient;
![]()
![]() public partial class PowerORM : System.Web.UI.Page
public partial class PowerORM : System.Web.UI.Page
![]()
![]()
![]() {
{
![]() protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e)
![]()
![]() 
    ![]() {
{
![]() string strConnection = "Server=127.0.0.1;User ID=sa;Password=qqww;Persist Security Info=True;DataBase=Northwind;";
        string strConnection = "Server=127.0.0.1;User ID=sa;Password=qqww;Persist Security Info=True;DataBase=Northwind;";
![]() string strSQL = "SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]";
        string strSQL = "SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]";
![]() IList myList;
        IList myList;
![]() using (SqlDataReader myReader = SqlHelper.ExecuteReader(strConnection, CommandType.Text, strSQL))
        using (SqlDataReader myReader = SqlHelper.ExecuteReader(strConnection, CommandType.Text, strSQL))
![]()
![]() 
        ![]() {
{
![]() myList = myPowerORM.FillHelper.Fill((new myPowerORM.Customer()).GetType(), myReader);
            myList = myPowerORM.FillHelper.Fill((new myPowerORM.Customer()).GetType(), myReader);
![]() }
        }
![]()
![]() Response.Write("<pre>");
        Response.Write("<pre>");
![]()
![]() foreach (object o in myList)
        foreach (object o in myList)
![]()
![]() 
        ![]() {
{
![]() myPowerORM.Customer c = (myPowerORM.Customer)o;
            myPowerORM.Customer c = (myPowerORM.Customer)o;
![]()
![]() Response.Write(c.CustomerID+"\t"+c.CompanyName+"\t"+c.ContactNameI+"\n<br>");
            Response.Write(c.CustomerID+"\t"+c.CompanyName+"\t"+c.ContactNameI+"\n<br>");
![]() }
        }
![]()
![]() Response.Write("</pre>");
        Response.Write("</pre>");
![]()
![]()
![]() }
    }
![]() }
}
![]()
![]()
![]()
![]()
![]()
![]() namespace myPowerORM
namespace myPowerORM
![]()
![]()
![]() {
{
![]() public class Customer
    public class Customer
![]()
![]() 
    ![]() {
{
![]() private string _customerID, _companyName, _contactName;
        private string _customerID, _companyName, _contactName;
![]()
![]() [Column("CustomerID")]
        [Column("CustomerID")]
![]() public string CustomerID
        public string CustomerID
![]()
![]() 
        ![]() {
{
![]()
![]() get
            get ![]() { return _customerID; }
{ return _customerID; }
![]()
![]() set
            set ![]() { _customerID = value; }
{ _customerID = value; }
![]() }
        }
![]()
![]() [Column("CompanyName")]
        [Column("CompanyName")]
![]() public string CompanyName
        public string CompanyName
![]()
![]() 
        ![]() {
{
![]()
![]() get
            get ![]() { return _companyName; }
{ return _companyName; }
![]()
![]() set
            set ![]() { _companyName = value; }
{ _companyName = value; }
![]() }
        }
![]()
![]() [Column("ContactName")]
        [Column("ContactName")]
![]() public string ContactNameI
        public string ContactNameI
![]()
![]() 
        ![]() {
{
![]()
![]() get
            get ![]() { return _contactName; }
{ return _contactName; }
![]()
![]() set
            set ![]() { _contactName = value; }
{ _contactName = value; }
![]() }
        }
![]()
![]() public Customer()
        public Customer() ![]() { }
{ }
![]() }
    }
![]()
![]() [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
![]() public class ColumnAttribute : Attribute
    public class ColumnAttribute : Attribute
![]()
![]() 
    ![]() {
{
![]() private string _columnName = null;
        private string _columnName = null;
![]()
![]() public string ColumnName
        public string ColumnName
![]()
![]() 
        ![]() {
{
![]()
![]() get
            get ![]() { return _columnName; }
{ return _columnName; }
![]() }
        }
![]()
![]() public ColumnAttribute(string columnName)
        public ColumnAttribute(string columnName)
![]()
![]() 
        ![]() {
{
![]() _columnName = columnName;
            _columnName = columnName;
![]() }
        }
![]() }
    }
![]()
![]()
![]() public class FillHelper
    public class FillHelper
![]()
![]() 
    ![]() {
{
![]() public static IList Fill(Type rowType, IDataReader reader)
        public static IList Fill(Type rowType, IDataReader reader)
![]()
![]() 
        ![]() {
{
![]() ArrayList dataList = new ArrayList();
            ArrayList dataList = new ArrayList();
![]() while (reader.Read())
            while (reader.Read())
![]()
![]() 
            ![]() {
{
![]() object item = Activator.CreateInstance(rowType, false); //使用与指定参数匹配程度最高的构造函数创建指定类型的实例
                object item = Activator.CreateInstance(rowType, false); //使用与指定参数匹配程度最高的构造函数创建指定类型的实例
![]() foreach (MemberInfo mi in rowType.GetMembers())
                foreach (MemberInfo mi in rowType.GetMembers())
![]()
![]() 
                ![]() {
{
![]() foreach (ColumnAttribute attr in mi.GetCustomAttributes(typeof(ColumnAttribute), false))
                    foreach (ColumnAttribute attr in mi.GetCustomAttributes(typeof(ColumnAttribute), false))
![]()
![]() 
                    ![]() {
{
![]() int index = reader.GetOrdinal(attr.ColumnName); //在给定列名称的情况下获取列序号
                        int index = reader.GetOrdinal(attr.ColumnName); //在给定列名称的情况下获取列序号
![]() if (index != -1)
                        if (index != -1)
![]()
![]() 
                        ![]() {
{
![]() if (mi.MemberType == MemberTypes.Field)
                            if (mi.MemberType == MemberTypes.Field)
![]() ((FieldInfo)mi).SetValue(item, reader.GetValue(index));
                                ((FieldInfo)mi).SetValue(item, reader.GetValue(index));
![]() else if (mi.MemberType == MemberTypes.Property)
                            else if (mi.MemberType == MemberTypes.Property)
![]() ((PropertyInfo)mi).SetValue(item, reader.GetValue(index), null);
                                ((PropertyInfo)mi).SetValue(item, reader.GetValue(index), null);
![]() }
                        }
![]() }
                    }
![]() }
                }
![]() dataList.Add(item);
                dataList.Add(item);
![]() }
            }
![]() return dataList;
            return dataList;
![]() }
        }
![]()
![]() public FillHelper()
        public FillHelper() ![]() { }
{ }
![]() }
    }
![]() }
}