使用Assembly生成带参数的泛型实例
2008-01-12 10:04
323 查看
public class DataAccess<T>
{
protected static readonly string _path = ConfigurationSettings.AppSettings["WebDAL"];
public static IDAL.ITreeTable<T> CreatTreeTable(string tableName, string idName, string parentIdName, string displayOrderName)
{
if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(idName) || string.IsNullOrEmpty(parentIdName))
throw new Exception("tableName,idName,parentIdName,displayOrder必须设置.");
string className = _path + ".TreeTable`1[[" + typeof(T).FullName + "," + typeof(T).Assembly.ToString() + "]]";
Assembly assembly = Assembly.Load(_path);
Type t = assembly.GetType(className);
object[] args = new object[4];
args[0] = tableName;
args[1] = idName;
args[2] = parentIdName;
args[3] = displayOrderName;
return (IDAL.ITreeTable<T>)Activator.CreateInstance(t, args);
}
}
{
protected static readonly string _path = ConfigurationSettings.AppSettings["WebDAL"];
public static IDAL.ITreeTable<T> CreatTreeTable(string tableName, string idName, string parentIdName, string displayOrderName)
{
if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(idName) || string.IsNullOrEmpty(parentIdName))
throw new Exception("tableName,idName,parentIdName,displayOrder必须设置.");
string className = _path + ".TreeTable`1[[" + typeof(T).FullName + "," + typeof(T).Assembly.ToString() + "]]";
Assembly assembly = Assembly.Load(_path);
Type t = assembly.GetType(className);
object[] args = new object[4];
args[0] = tableName;
args[1] = idName;
args[2] = parentIdName;
args[3] = displayOrderName;
return (IDAL.ITreeTable<T>)Activator.CreateInstance(t, args);
}
}
相关文章推荐
- UWP项目生成错误: 未能使用“CompileXaml”任务的输入参数初始化该任务。“CompileXaml”任务不支持“PlatformXmlDir”参数。请确认该参数存在于此任务中,并且是可设置的公共实例属性。
- 泛型约束where条件的使用(通过类型参数动态反射创建实例)
- More Effective C# Item8 :尽可能使用泛型方法,除非需要将类型参数用于实例的字段中
- 泛型约束where条件的使用(可以通过类型参数动态反射创建实例)
- 尽可能使用泛型方法,除非需要将类型参数用于实例的字段
- mybatis generator生成 example类的实例函数使用
- qemu使用实例和常用参数
- 第二个工作流实例--使用WorkflowInvoker向工作流传递参数
- mysql使用substring分割参数实例
- 解决变参数问题:va_list、va_start、vsnprintf、va_end的使用方法和实例
- 报表设计中参数、脚本的使用以及生成系统时间
- 使用RSA、MD5对参数生成签名与验签
- 使用JavaScript生成罗马字符的实例代码
- PHP curl CURLOPT_RETURNTRANSFER参数的作用使用实例
- 编写高质量代码改善C#程序的157个建议——建议42:使用泛型参数兼容泛型接口的不可变性
- subplots与figure函数参数解释说明以及简单的使用脚本实例
- 使用PDFLib生成PDF文档,C代码实例--使用特色
- 使用wsimport命令生成webService客户端代码实例
- C++中main函数中参数argc和argv的使用实例
- 使用eclipse JDT compile class,解决 无法确定 X 的类型参数;对于上限为 X,java.lang.Object 的类型变量 X,不存在唯一最大实例