• C#动态加载类


    using System;
    using System.Data;
    using System.Reflection;
    using System.Web;
    using System.Web.UI;

    namespace WebApplication1
    {
        
    /// <summary>
        
    /// Class1 的摘要说明。
        
    /// </summary>

        public class Servlets:System.Web.UI.Page
        
    {
            
            
    private void Page_Load(object sender, System.EventArgs e)
            
    {
                
    // 在此处放置用户代码以初始化页面
            
                Response.Write(InitPage());
                AfterLoadPage();
                
    //string aliasName="test2.Class2";

                
    //result.AppAssembly = ((ClassItem)item).ClassAssembly;
                
    //return result;
                
                
    //Assembly assem= Assembly.Load(aliasName);
                
                Type[] helloType 
    = LoadAssembly("test2");
                
                MethodInfo printMethod 
    = helloType[0].GetMethod("reback");
                
                Object obj 
    = Activator.CreateInstance(helloType[0]);
                Response.Write(printMethod.Invoke(obj,
    null));
                
    //Object[] args = new Object[1];
                
                
    //args[0] = "From CSharp Late Bound";
                
    //printMethod.Invoke(obj, args);
    //            
                
    //Response.Write(result);


            }


            
    public Type[] LoadAssembly(string filename)

            
    {

                Type[] functionList 
    = new Type[10];

                Assembly assembly 
    = AppDomain.CurrentDomain.Load(filename);

                    
    int i=0;

                
    foreach (Type t in assembly.GetTypes())

                
    {
                    
                    functionList[i]
    =t;
                    i
    =i+1;

                }
       

                
    return functionList;

            }
     



            
    protected virtual void AfterLoadPage()
            
    {
            }

            
            
    protected virtual string InitPage()
            
    {
                
    return "BASE";
            }


            
    //Web 窗体设计器生成的代码
            Web 窗体设计器生成的代码

        }

    }

  • 相关阅读:
    odoo14系列笔记-基本进销存(二)
    odoo14系列笔记-基本进销存(一)
    PVE另一种方法使用中科大的镜像服务器 NGINX反向代理
    git 国内加速
    VirtualBox开启套娃模式-打开嵌套 VT-x/AMD-V 功能
    K8S集群安装(基于DEIBAN,proxmox)
    JS语法 ES6、ES7、ES8、ES9、ES10、ES11、ES12新特性
    8个非常实用的Vue自定义指令
    require和import的区别
    js异步加载之defer、async、type=module
  • 原文地址:https://www.cnblogs.com/chinatefl/p/279656.html
Copyright © 2020-2023  润新知