[英]register eventhandler for Office 2013 event in vs 2010 by reflections in C#
我有一个使用Visual Studio 2010用C#编写的Outlook 2010加载项项目。
由于外接程序总体上可以在Outlook 2013中正常工作,因此我只想进行一些修改,以防止Outlook 2013中新的InlineResponse功能出现问题。
我想为InlineResponse事件注册一个事件处理程序,而无需升级到VS 2012(因为删除了安装程序项目)。 我阅读了有关使用反射获取新事件的信息。
我没有任何异常,但是该事件不会触发我的处理程序(未调用OnInlineResponse)。
public partial class ThisAddIn
{
Outlook.Explorer _explorer;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
_explorer = Application.ActiveExplorer();
AddInlineResponseHandler();
}
private void AddInlineResponseHandler()
{
var einfo = _explorer.GetType().GetEvent("InlineResponse", BindingFlags.Public | BindingFlags.Instance);
if (einfo != null)
{
var handler = Delegate.CreateDelegate(einfo.EventHandlerType, this, this.GetType().GetMethod("OnInlineResponse", BindingFlags.NonPublic | BindingFlags.Instance), false);
einfo.AddEventHandler(_explorer, handler);
}
}
private void OnInlineResponse()
{
System.Windows.Forms.MessageBox.Show("InlineResponse");
}
}
关于如何实现预期行为的任何建议?
加文·史密斯(Gavin Smyth)(撰写了有关使用反射的文章)非常善良,可以为我解答我们的实现之间的差异:
我和您之间的唯一区别是OnInlineResponse接受了一个参数,即新创建的邮件项-请参阅http://msdn.microsoft.com/zh-cn/library/office/jj229061-即,我的方法已定义如:
private void OnInlineResponse(object item) { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.