zoukankan      html  css  js  c++  java
  • 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 窗体设计器生成的代码

        }

    }

  • 相关阅读:
    Shell 函数
    Shell 流程控制
    Shell test 命令
    Shell echo命令
    python 类、模块、包的区别
    postgresql vacuum table
    ssh连接断开后 shell进程退出
    ubuntu 搭建 svn服务器,使用http方式访问
    如何查看apache加载了哪些模块
    maven 的使用
  • 原文地址:https://www.cnblogs.com/chinatefl/p/279656.html
Copyright © 2011-2022 走看看