要调用方法的话非常简单。但是这么做意义不明。如果不考虑参数的话伪代码如下。实现是肯定可以实现的但是为什么要实现?
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class Program
{
public delegate void ButtonClickDelegate();
static void Main(string[] args)
{
Assembly assembly = Assembly.LoadFrom(@"TestVsto.dll");
Type type = assembly.GetType("TestVsto.Ribbon1");
MethodInfo method = type.GetMethod("Button1_Click", BindingFlags.Instance | BindingFlags.NonPublic);
RuntimeHelpers.PrepareMethod(method.MethodHandle);
IntPtr ptr = method.MethodHandle.GetFunctionPointer();
ButtonClickDelegate del = (ButtonClickDelegate)Marshal.GetDelegateForFunctionPointer(ptr, typeof(ButtonClickDelegate));
del();
}
}
}
|