附加事件动态对象 [英] Attach event to dynamic object

查看:205
本文介绍了附加事件动态对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的休耕的方式与COM对象的C#动态目标:

I create a c# dynamic object of a COM-Object on the fallowing way:

dynamic pdfCreator = Activator.CreateInstance(
                       Type.GetTypeFromProgID("PDFCreator.clsPDFCreator"));

类clsPDFCreator是定义一个事件调用eReady。但是,当我尝试注册像

The class clsPDFCreator is defining an event calling eReady. But when I try to register an Eventhandler like

pdfCreator.eReady += _PDFCreator_eReady;

我得到错误信息运算符+ =不能应用于类型的操作数动态和方法组'。

I get the error message "Operator '+=' cannot be applied to operands of type 'dynamic' and 'method group'".

如何注册一个事件处理程序到被宣布为动态对象的事件?

推荐答案

这个怎么样:

public delegate void eReadyHandler();

static void Main(string[] args)
{
    var comType = Type.GetTypeFromProgID("PDFCreator.clsPDFCreator");
    dynamic pdfCreator = Activator.CreateInstance(comType);
    //dynamic pdfCreator = new PDFCreator.clsPDFCreator();

    //pdfCreator.eReady = null;
    pdfCreator.eReady += new eReadyHandler(_PDFCreator_eReady);
}

public static void _PDFCreator_eReady()
{

}

这篇关于附加事件动态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆