日期:2014-05-17  浏览次数:20495 次

请问以下代码可有精简方案?
C# code
void crawler_OnCrawlerThreadEnd(object sender, Nipusa.Crawler.EventArguments.CrawlerThreadEndEventArgs args)
        {
            //throw new NotImplementedException();
        }

        void crawler_OnError(object sender, Nipusa.Crawler.EventArguments.CrawlerErrorEventArgs args)
        {
            //throw new NotImplementedException();
        }

        void crawler_OnFindNewUri(object sender, Nipusa.Crawler.EventArguments.CrawlerFindNewUriEventArgs args)
        {
           // throw new NotImplementedException();
        }

        void crawler_OnUriFetchComplete(object sender, Nipusa.Crawler.EventArguments.CrawlerUriFetchCompleteEventArgs args)
        {
            if (plugins_list.ContainsKey(args.CrawlerObject.CrawlerName))
            {
                List<PluginBase> plugins = plugins_list[args.CrawlerObject.CrawlerName];
                foreach (PluginBase pb in plugins)
                {
                    pb.OnUriFetchComplete(sender, args);
                }
            }
        }

        void crawler_OnUriBeginRequest(object sender, Nipusa.Crawler.EventArguments.CrawlerUriBeginRequestEventArgs args)
        {
            ThreadMessage((sender as Nipusa.Crawler.NipusaCrawler).CrawlerName, args.ThreadName+":"+args.RequestUri.ToString());

            if (plugins_list.ContainsKey(args.CrawlerObject.CrawlerName))
            {
                List<PluginBase> plugins = plugins_list[args.CrawlerObject.CrawlerName];
                foreach (PluginBase pb in plugins)
                {
                    pb.OnUriBeginRequest(sender, args);
                }
            }
        }

如上所示,大意是循环调用所有注册的插件的方法。但这样一来。每个事件方法里都要有个foreach。很臃肿。或者有没有办法直接把类中的方法注册为事件的方法?

但貌似event+=new delegate(class.method);通不过?