Skip to content

Instantly share code, notes, and snippets.

@Flayed
Last active December 16, 2017 12:35
Show Gist options
  • Save Flayed/87a829ed3b49fd9177f28cfc605846ed to your computer and use it in GitHub Desktop.
Save Flayed/87a829ed3b49fd9177f28cfc605846ed to your computer and use it in GitHub Desktop.
Enumerate Class Constants
public static class MagicStrings
{
public const string Potato = "Potato";
public const string Tomato = "Tomato";
private static string[] _strings;
public static string[] Strings
{
get
{
if (_strings != null) return _strings;
_strings = typeof(MagicStrings).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
.Where(f => f.IsLiteral && !f.IsInitOnly && f.FieldType == typeof(string))
.Select(f => (string)f.GetValue(null)).ToArray();
return _strings;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment