Enum to list as an extension?

后端 未结 6 1326
花落未央
花落未央 2021-02-19 19:00

I have various enums that I use as sources for dropdown lists, In order to provide for a user-friendly description, I added a Description attribute to each enum, an

6条回答
  •  春和景丽
    2021-02-19 19:32

    Try replacing

    .ToDictionary(k => k, v => v.GetAttributeOfType().Description)
    

    with

    .Select(t => new { k = t, v = t.GetAttributeOfType().Description)
    .ToDictionary(s => s.k, s => s.v)
    

    In your example, the wrong overload of ToDictionary() is being called.

提交回复
热议问题