zoukankan      html  css  js  c++  java
  • C#反射

    Assembly assembly = Assembly.Load("project");
    Assembly assembly2 = Assembly.LoadFrom("project.dll");

    Module[] module = assembly.GetModules();
    foreach (Module item in module)
    {
    Console.WriteLine("module:" + item);

    }

    //获取namespace,class

    Type[] types = assembly.GetTypes();

    foreach (Type item in types)
    {
    Console.WriteLine("type:" + item);
    Type t = item;
    MethodInfo[] methods = t.GetMethods();
    IEnumerable<MethodInfo> methodInfo = t.GetRuntimeMethods();
    foreach (MethodInfo methodInfoitem in methodInfo)
    {
    Console.WriteLine(" methodInfoitem:" + methodInfoitem);
    }
    Console.WriteLine();
    foreach (var items in t.BaseType.GetMembers())
    {
    Console.WriteLine("BaseType:" + items);
    }
    foreach (MethodInfo method in methods)
    {
    Console.WriteLine("方法:" + method);
    Type typeopen = assembly.GetType(Convert.ToString(item));
    var user12 = Activator.CreateInstance(typeopen);
    string chuan = Convert.ToString(method);
    string strs = chuan.Substring(chuan.IndexOf(" ") + 1, chuan.Length - chuan.IndexOf(" ") - 1);
    strs = strs.Substring(0, strs.IndexOf("("));
    if (strs == "PublicShow")
    {

    typeopen.InvokeMember(strs,
    BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, user12,
    null);

    }

    }
    }

  • 相关阅读:
    使用 Vim 搭建 JavaScript 开发环境
    SpaceVim 语言模块 erlang
    SpaceVim 语言模块 lua
    SpaceVim 语言模块 python
    SpaceVim 语言模块 elixir
    SpaceVim 语言模块 dart
    SpaceVim 语言模块 elm
    如何配置 SpaceVim
    彻底理解浏览器缓存机制
    react-创建react元素
  • 原文地址:https://www.cnblogs.com/david_king/p/4182727.html
Copyright © 2011-2022 走看看