zoukankan      html  css  js  c++  java
  • 使用Assembly生成带参数的泛型实例

    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);
            }
    }

  • 相关阅读:
    C++之Static与Const
    LInux主机与虚拟机网络链接
    C#数据类型与数据类型转化
    C#网编Console(二)
    C#网编Winform(三)
    C#网编基础类与API(一)
    C实现CPU大小端判断
    QT程序图标设置
    四、初识Socket套接字API
    C++之继承(二)
  • 原文地址:https://www.cnblogs.com/lswweb/p/1035997.html
Copyright © 2011-2022 走看看