zoukankan      html  css  js  c++  java
  • 反射调用DLL

    public static type GetClassType(string ClassName,string dllname)

    {

        Type ClassType =null;

         foreach(Assembly am in AppDomain.CurrentDomain.GetAssemblies())

    {

          if (am.FullName.Contains(dllname))

    {

      ClassType=am.GetType(ClassName);

      if (ClassType !=null) break;

    }
    }

    if (ClassType==null)

    {

    string filename=string.Empty;

    if (dllname.EndsWith(".dll"))

    {

    filename=Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllname);

    }

    else

     filename=string.Format("{0}.dll ",AppDomain.CurrentDomain.BaseDirectory, dllname));

    Assembly asm=Assembly.LoadFile(filename);

    ClassType =asm.GetType(ClassName);

    }

    return ClassType;

    }

    private static Dictionary <int,object> ServiceDe=new Dictionary<int,object>();

    delegate Result ActionDelegate<T>(T Data);

    private static Result ReflectionMethod<T>(FormShowRequest request)

    {

    object doAction =null;

    string dllname =request.module;

    string classname=request.action;

    string method=request.method;

    param sdata=request.param;

    Result result=new Result();

    string strKey=dllname+“,”+classname+","+method;

    int hashCode=strKey.GetHashCode();

    if (!ServiceDelegates.ContainsKey(hashCode))

    {

    Type clsname =GetClassType(classname,dllname);

    object action=clsname.GetConstructor(Type.EmptyTypes).Invoke(null);

    doAction =Delegate.CreateDelegate(typeof(ActionDelegate<T>),action,method);

    if (ServiceDelegates!=null && doAction!=null)

    ServiceDelegates.Add(hashCode,doAction);

    }

    else

    {

    doAction=ServiceDelegates[hashCode];

    }

    if (doAction!=null)

    {

    result =((ActionDelegate<param>)doAction)(sdata);

    return result;

    }

    else

    {

    result=new Result();

    result.errors=“反射调用错误!”

    }
    }

  • 相关阅读:
    短连接生成
    google 定位 标记 地址解码 逆解码
    Laravel 文件上传
    Laravel
    对接航信开票-在线二维码开票
    win 下 composer 安装
    对接美团外卖开放平台
    IOS 弹框在微信中导致输入框等失焦 偏移问题解决
    微信公众号-高德地图实例
    对接百度地图API 实现地址转经纬度
  • 原文地址:https://www.cnblogs.com/huzige/p/7675540.html
Copyright © 2011-2022 走看看