如何使用c#中的反射向字典添加值?

3 c# reflection

我有以下词典:

private Dictionary<string, double> averages = new Dictionary<string, double>();
Run Code Online (Sandbox Code Playgroud)

现在我想使用反射添加两个额外的值.我可以检索字段信息,但我还需要做什么?

FieldInfo field = ProjectInformation.SourceManager.GetType().GetField("averages");
if (field != null)
{
    //what should be here?
}
Run Code Online (Sandbox Code Playgroud)

ren*_*ene 5

MethodInfo mi = field.FieldType.GetMethodInfo("set_Item");
Object dict = field.GetValue(ProjectInformation.SourceManager);
mi.Invoke(dict, new object[] {"key", 0.0} );
Run Code Online (Sandbox Code Playgroud)