如何使用.NET生成C#源代码

47 篇文章 0 订阅

 

 

 

 该文章中的数据访问层中有一个属性一个字段以及一个方法。属性是一个获得连接对象的属性,字段是一个连接对象的私有成员,方法是一个Get方法,得到一个查询结果集。源代码生成以后就象下面这个样子:
using System;
using System.Data;
using System.Data.SqlClient;

namespace Power.Cuike519 {
   
   
    public class PowerDataAccess {
       
        private SqlConnection m_connection;
       
        public PowerDataAccess() {
        }
       
        public virtual SqlConnection Connection {
            get {
                return this.m_connection;
            }
            set {
                this.m_connection = value;
            }
        }
       
        public virtual DataSet GetAllAuthors(string s_State) {
            try {
                if (this.m_connection!=null) {
                    System.Data.SqlClient.SqlDataAdapter da = new SqlDataAdapter(string.Format("select * from authors where state like '{0}'",s_State),this.m_connection);
                    System.Data.DataSet ds = new DataSet();
                    da.Fill(ds);
                    return ds;
                }
                else {
                    return null;
                }
            }
            catch (System.ApplicationException ex) {
                throw ex;
            }
            finally {
                this.m_connection.Close();
            }
        }
    }
}
       

 

using System.IO;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.CodeDom;
using System.Reflection;

 

 

srouce: 如何使用.NET生成C#源代码

 

 

在找MyGeneration时发现一个网站:http://www.codegeneration.net/
上面收集了一些和代码生成有关的资料。特别是代码生成的工具,看得人眼花缭乱。
伤心的是C#的代码生成工具开源和免费的不太多

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值