C# cast Dictionary to Dictionary (Involving Reflection)

前端 未结 8 980
无人及你
无人及你 2021-01-04 10:04

Is it possible to cast a Dictionary to a consistent intermediate generic type? So I would be able to cast <

8条回答
  •  一生所求
    2021-01-04 10:17

    Yes It is possible to cast the FieldInfo to Dictionary as below

    This is one example, I have used in my code

    Dictionary 
                    GetTheDict = FilesAndPaths.GetType()
                                 .GetFields()
                                 .Where(f => f.Name.Equals(pLoadFile))
                                 .Select(f => (Dictionary)f.GetValue(FilesAndPaths))
                                 .Single();
    

提交回复
热议问题