本文主要是介绍Net反射应用(Assembly),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1 使用反射创建新对象
//使用反射创建新对象
private static string type = ConfigurationManager.AppSettings["FactoryType"];
public static IDAL.INews CreateNews()
{
return (IDAL.INews)Assembly.Load(type + "DAL").CreateInstance(type + "DAL.News");
}
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){var content=codeElement.innerText;if(window.clipboardData==null){window.alert("您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function LineNumberVisible(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i
//通过反射生成插入语句
private string ParserCommandText(object entity)
{
var t = entity.GetType();
var tableName = t.Name;
//初始化前缀
var sql = new StringBuilder("INSERT INTO ");
sql.AppendFormat("{0}", tableName);
//初始化参数
var fields = new List<string>();
var fieldParameterName = new List<string>();
foreach (var p in t.GetProperties())
{
fields.Add(p.Name);
fieldParameterName.Add("@" + p.Name);
}
sql.AppendFormat("({0}) ", string.Join(",", fields.ToArray()));
sql.AppendFormat("VALUES({0})", string.Join(",", fieldParameterName.ToArray()));
return sql.ToString();
}
这篇关于Net反射应用(Assembly)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!