将<T>列入字典

chu*_*h97 3 c# linq generics dictionary

我有一个List<CustomObject> 有3个属性A,B,C,我需要的是将这个List转换为一个字典,所以结果看起来像

Dictionary<string,object>
(Property name) A = Value of A
(Property name) B = Value of B
(Property name) C = Value of C
Run Code Online (Sandbox Code Playgroud)

请建议......

Lee*_*Lee 5

CustomObject instance = new CustomObject();
var dict = instance.GetType().GetProperties()
    .ToDictionary(p => p.Name, p => p.GetValue(instance, null));
Run Code Online (Sandbox Code Playgroud)