知道类名和方法名的字符串怎么得到这个方法名 通过委托传递我现在从xml中间读取类名和方法名 但是都是字符串 我需要一个实例化的类的方法名 当委托的参数传递给一个函数
我现在不知道怎么传递 清高手指点
object[] parameters = { this.Application };
Assembly ass = Assembly.Load("MenuEvent"); //MenuEvent是引用的dll System.Type type = ass.GetType("MenuEvent.EventTest"); object classObject = Activator.CreateInstance(type, parameters);
MethodInfo methodInfo = type.GetMethod("a3"); //a3 是方法 MenuEventHandle MenuEventName = delegate(Microsoft.Office.Core.CommandBarButton cmdBarbutton, ref bool cancel)
{
object[] parameters2 = { cmdBarbutton, cancel };
methodInfo.Invoke(classObject, parameters2);
};
if (Before == "null"&&faceId=="null")
AddMenuButton(Caption, MenuEventName);
我用的匿名方法 可是按钮开始能用议会就不能用了 估计是被释放了 请教高手怎么写 或者能用别的方法实现么
我现在不知道怎么传递 清高手指点
object[] parameters = { this.Application };
Assembly ass = Assembly.Load("MenuEvent"); //MenuEvent是引用的dll System.Type type = ass.GetType("MenuEvent.EventTest"); object classObject = Activator.CreateInstance(type, parameters);
MethodInfo methodInfo = type.GetMethod("a3"); //a3 是方法 MenuEventHandle MenuEventName = delegate(Microsoft.Office.Core.CommandBarButton cmdBarbutton, ref bool cancel)
{
object[] parameters2 = { cmdBarbutton, cancel };
methodInfo.Invoke(classObject, parameters2);
};
if (Before == "null"&&faceId=="null")
AddMenuButton(Caption, MenuEventName);
我用的匿名方法 可是按钮开始能用议会就不能用了 估计是被释放了 请教高手怎么写 或者能用别的方法实现么
再说如果真是被释放了,那你调用的时候会弹出空指针错误的.
散分!!!!!!!!!
先来先得了!!!!!!!!!!!!!!!!呵呵!!!!!!!!!!!!!!!!!!!!!!!!!