1

我能否确定某个功能是否已分配给某个事件?

例如(带有网络浏览器控制的标准 winforms 应用程序)

namespace Crawler {
    public partial class Form1 : Form {

        WebCrawler.manager m;

        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            system.windows.forms.webbrowser wb = new system.windows.forms.webbrowser();
            wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(foo);

            //[... Some other code ...]

            /* [Begin Example] */

            if (wb.DocumentCompleted.Contains(foo){

                // Behave Normally

            }else {

                // Do Something Else...

            }
        }
    }
}

而且,如果我可以做我上面描述的事情,那该怎么做?

4

1 回答 1

1

你可以打电话Deletegate.GetInvocationList

这是一个例子:

using System;
using System.Linq;

class Program
{
    static event Action foo;

    static void bar() { }

    static void Main()
    {
        foo += bar;

        bool contains = foo
            .GetInvocationList()
            .Cast<Action>()
            .Contains(bar);
    }   
}
于 2009-05-11T15:55:06.827 回答