Results 1 to 2 of 2

Thread: Looking for simplier or shorter way to convert enum description attributes to a list

Threaded View

  1. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Looking for simplier or shorter way to convert enum description attributes to a l

    The code is not necessarily shorter overall but check out these classes I created for this purpose:

    http://www.vbforums.com/showthread.php?552563

    In your case, the code would be:
    csharp Code:
    1. var model = new EnumDescriptorCollection<CaseParty.PRIORITY_TYPE>().Select(ed => ed.ToString()).ToList();
    That said, you could already be using this:
    csharp Code:
    1. var model = Enum.GetValues(typeof(CaseParty.PRIORITY_TYPE))
    2.                 .Cast<CaseParty.PRIORITY_TYPE>()
    3.                 .Select(pt => pt.ToDescriptionString())
    4.                 .ToList();
    Last edited by jmcilhinney; Feb 22nd, 2019 at 10:40 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width