Last active
December 16, 2017 12:35
-
-
Save Flayed/87a829ed3b49fd9177f28cfc605846ed to your computer and use it in GitHub Desktop.
Enumerate Class Constants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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