1

I have researched and it seems that most is bouncing around the problem I have.

@Code
@Imports System.ComponentModel
Dim values = New SelectList([Enum].GetNames(GetType(myEnum)).GetAttribute<DisplayAttribute>()
End Code

The last pararenthesis has a blue line under it and when hover tells me an expression is expected. I want to capture the display name from my enum and have tried many things found on the google search without success. Why am I getting the expression expected error?

Attempted to incorporate and now getting at end parenthesis
Dim type = typeof(MyEnum) ls is expected.

m.rice
  • 139
  • 1
  • 10
  • Possible duplicate of [Getting attributes of Enum's value](http://stackoverflow.com/questions/1799370/getting-attributes-of-enums-value) – Steve Dec 03 '15 at 21:44
  • A VB version http://stackoverflow.com/a/25477800/1070452 (assuming "display name" means `DescriptionAttribute`) – Ňɏssa Pøngjǣrdenlarp Dec 03 '15 at 21:46
  • Imports System.Reflection as well as System.ComponentModel Dim value = [Enum].GetNames(GetType(MyEnum) Dim descry as New List(of String) For each v in value descry.Add(GetDescription.(Ctype(v, [Enum]))) tells me that GetDescription is not declared – m.rice Dec 03 '15 at 22:13

1 Answers1

0

You might want to have a look at this awesome NuGet package called UnconstrainedMelody from Jon Skeet.

https://www.nuget.org/packages/UnconstrainedMelody/

Helpful static methods (or extension methods) for enums and delegates, with constraints which can't be expressed in regular C#.

Have a look at the functions UnconstrainedMelody.Enums.GetNames() and UnconstrainedMelody.Enums.GetValues()

MrDeveloper
  • 1,041
  • 12
  • 35