Dictionary with Delegates of different types: Cleaner, non string method names?

后端 未结 1 1355
失恋的感觉
失恋的感觉 2021-01-13 13:49

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

... Constructor()
{
      parseDictionary = new Dictionary()
            {
         


        
相关标签:
1条回答
  • 2021-01-13 14:11

    Just cast to the right kind of delegate:

    parseDictionary = new Dictionary<typeOfStream, Delegate>()
    {
        { typeOfStream.SOME_ENUM_VAL, (ParseDelegate<string>) MyMethod) },
        { typeOfStream.SOME_OTHER_ENUM_VAL, (ParseDelegate<XmlNode>) MyOtherMethod }
    };
    
    0 讨论(0)
提交回复
热议问题