Skip to content

Instantly share code, notes, and snippets.

@nycdotnet
Created October 9, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nycdotnet/43dc3484dd050190296020862141fff9 to your computer and use it in GitHub Desktop.
Save nycdotnet/43dc3484dd050190296020862141fff9 to your computer and use it in GitHub Desktop.
Get Constants On Type
/// <summary>
/// Enumerates constants on a type.
/// </summary>
public static IEnumerable<FieldInfo> GetConstantsOnType(Type TypeToReflect)
{
return TypeToReflect.GetFields().Where(f => f.IsStatic && f.IsLiteral);
}
/// <summary>
/// Enumerates constants on a type of a type.
/// </summary>
public static IEnumerable<FieldInfo> GetConstantsOnTypeOfType(Type TypeToReflect, Type TypeToFind)
{
return GetConstantsOnType(TypeToReflect).Where(f => f.FieldType == TypeToFind);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment