The documentation comes from the Markdown files in the source code, so is always up-to-date but available only in English. Enjoy!
Just some extensions for any kind of enum.
Just parses the enum using Enum.Parse, but does the casting for you.
public static T ToEnum<T>(this string str) where T : struct
public static T ToEnum<T>(this string str, bool ignoreCase) where T : struct
Example:
"Monday".ToEnum<DayOfWeek>()); //returns DayOfWeek.Monday
"monday".ToEnum<DayOfWeek>()); //throws ArgumentException
"Monday".ToEnum<DayOfWeek>(true)); //returns DayOfWeek.Monday
"monday".ToEnum<DayOfWeek>(true)); //returns DayOfWeek.Monday
Returns all the values in an enum type in a typed array:
public static T[] GetValues<T>()
Example:
EnumExtensions.GetValues<DayOfWeek>();
//Returns: new DayOfWeek[]{DayOfWeek.Sunday, DayOfWeek.Monday, ... }
Just as Enum.IsDefined but saving you to do the typeof(MyEnum)
public static bool IsDefined<T>(T value) where T : struct
Example:
EnumExtensions.IsDefined(DayOfWeek.Monday); //returns true
EnumExtensions.IsDefined((DayOfWeek)10); // returns false
Returns the minimum flag in a int (useful for enums decorated with FlagsAttribute).
public static int MinFlag(int value)
public static int MaxFlag(int value)
Example:
//Binary representation of 14 = 1110 = 8 + 4 + 2
EnumExtensions.MinFlag(14); //Returns 2
EnumExtensions.MaxFlag(14); //Returns 8
© Signum Software. All Rights Reserved.
Powered by Signum Framework