Skip to content

Instantly share code, notes, and snippets.

@srakowski
Forked from Flayed/Constants.cs
Last active December 16, 2017 00:22
Show Gist options
  • Save srakowski/4d54139ca06427878bcf7b39dc2f38d5 to your computer and use it in GitHub Desktop.
Save srakowski/4d54139ca06427878bcf7b39dc2f38d5 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