How do I .. use Reflection to get the values of an Enum at runtime

Thanks to:
http://www.vb-helper.com/howto_net_list_enum.html

Module Module1

Sub Main()

ForEach field As System.Reflection.FieldInfoInGetType(TestEnum).GetFields.Where(Function(f) f.IsLiteral)
  ‘Console.WriteLine(field.Name + vbTab + CInt(field.GetValue(Nothing)).ToString)
  Console.WriteLine(CInt(field.GetValue(Nothing)).ToString + ” “ + field.Name)
Next
Console.ReadLine()

End Sub

End Module

Public Enum TestEnum
  Cheese = 1
Wallace
Grommit
Wheelbarrows
End Enum

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: