Nic*_*ick 4 c# generics methods delegates dictionary
必须有一个更清洁的方法.目前我有:
... 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)
{
...
}
Run Code Online (Sandbox Code Playgroud)
我想摆脱"MyMethod"和MyOtherMethod并将它变成这个.MyMethod和this.MyOtherMethod.选项?
我对任何允许我使用Dictionary查找的解决方案持开放态度,并将我的数据mojo指向任意方法(以及具有任意一组参数的已定义方法)以进行解析.
Jon*_*eet 10
只是投射到合适的代表:
parseDictionary = new Dictionary<typeOfStream, Delegate>()
{
{ typeOfStream.SOME_ENUM_VAL, (ParseDelegate<string>) MyMethod) },
{ typeOfStream.SOME_OTHER_ENUM_VAL, (ParseDelegate<XmlNode>) MyOtherMethod }
};
Run Code Online (Sandbox Code Playgroud)