zoukankan      html  css  js  c++  java
  • C#反射:获取自定义类,动态调用方法

    枚举自定义实体

                var assembly = Assembly.LoadFrom(string.Format("{0}Blackice.App.Model.dll", BaseConfig.BinnPath));
                var types = assembly.GetTypes();
                foreach (var t in types)
                {
                    ButtonList += string.Format("<input style=\"400px;\" type=\"button\" onclick=\"CreateTable('{0}')\" value=\"创建表[{0}]\" />",
                                                t.Name);
                }
    

      创建表

            protected void Page_Load(object sender, EventArgs e)
            {
                if(!IsPostBack)
                {
                    var table = Request["t"];
                    CreateTable(table);
                }
            }
    
            protected void CreateTable(string tableName)
            {
                if (string.IsNullOrEmpty(tableName)) return;
                var name = string.Format("Blackice.App.Business.{0}", tableName);
                var assembly = Assembly.LoadFrom(string.Format(@"{0}Blackice.App.Business.dll", BaseConfig.BinnPath));
                var t = assembly.GetType(name);
                var obj = t.InvokeMember(null,
                                         BindingFlags.DeclaredOnly | 
                                         BindingFlags.Public | 
                                         BindingFlags.NonPublic |
                                         BindingFlags.Instance | 
                                         BindingFlags.CreateInstance, null, null, new object[] {});
                var blnTemp =(bool)t.InvokeMember("CreateTable", 
                                            BindingFlags.InvokeMethod | 
                                            BindingFlags.Public | 
                                            BindingFlags.Instance,null, obj, new object[] {});
                var script = blnTemp
                    ? tableName + "操作成功"
                    : tableName + "操作失败";
                Response.Write(string.Format("<script>parent.$F('status').innerHTML='{0}'</script>",script));
            }
    

      

  • 相关阅读:
    语义web相关概念
    python统计代码行数
    python编程常见小技巧
    windows10 搜索桌面搜索功能失效的解决
    python批量修改文件名称
    Python面向对象编程高级特性
    Python面向对象的编程注意细节
    python基础语法学习常见小问题
    备忘录模式
    适配器模式
  • 原文地址:https://www.cnblogs.com/blackice/p/2923062.html
Copyright © 2011-2022 走看看