字典< T,代表>不同类型的代表:清洁,无字符串的方法的名字呢? [英] Dictionary<T,Delegate> with Delegates of different types: Cleaner, non string method names?

查看:90
本文介绍了字典< T,代表>不同类型的代表:清洁,无字符串的方法的名字呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须有一个清洁器的方法。目前,我有:

There has to be a cleaner method. Currently I have:

... Constructor()
{
      parseDictionary = new Dictionary<typeOfStream, Delegate>()
            {
                {typeOfStream.SOME_ENUM_VAL, Delegate.CreateDelegate(typeof(ParseDelegate<string>), this, "MyMethod")},
                {typeOfStream.SOME_OTHER_ENUM_VAL, Delegate.CreateDelegate(typeof(ParseDelegate<XmlNode>), this, "MyOtherMethod")}
            };
}

public bool MyMethod(string some_string)
{
    ...
}

public bool MyOtherMethod(XmlNode some_node)
{
    ...
}

和我想摆脱的的MyMethod的和的 MyOtherMethod 的并使它的 this.MyMethod 的和的 this.MyOtherMethod 的。选项​​?

and I would like to get rid of "MyMethod" and MyOtherMethod and make it this.MyMethod and this.MyOtherMethod. Options?

我愿意接受任何解决方案,允许我使用词典查找,并与任意一串指向我的数据的魔力到任意方法(以及所定义的方法。参数)进行解析

I am open to any solution that allows me to use a Dictionary lookup, and point my data mojo into an arbitrary method (well a defined method with an arbitrary bunch of arguments) for parsing.

推荐答案

只投给合适的委托:

parseDictionary = new Dictionary<typeOfStream, Delegate>()
{
    { typeOfStream.SOME_ENUM_VAL, (ParseDelegate<string>) MyMethod) },
    { typeOfStream.SOME_OTHER_ENUM_VAL, (ParseDelegate<XmlNode>) MyOtherMethod }
};

这篇关于字典&LT; T,代表&GT;不同类型的代表:清洁,无字符串的方法的名字呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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