123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- namespace FirstGearGames.Utilities.Maths
- {
- public static class Enums
- {
-
-
-
-
-
-
-
- public static T FromString<T>(string text, T defaultValue)
- {
-
- if (string.IsNullOrEmpty(text))
- return defaultValue;
-
- if (!Enum.IsDefined(typeof(T), (string)text))
- return defaultValue;
-
- return (T)Enum.Parse(typeof(T), text, true);
- }
-
-
-
-
-
-
- public static bool Contains(this Enum whole, Enum part)
- {
-
-
-
-
-
- ulong wholeNum = Convert.ToUInt64(whole);
- ulong partNum = Convert.ToUInt64(part);
- return ((wholeNum & partNum) != 0);
- }
-
-
-
-
-
-
- public static bool ReverseContains(this Enum whole, Enum part)
- {
-
-
-
-
-
- ulong wholeNum = Convert.ToUInt64(whole);
- ulong partNum = Convert.ToUInt64(part);
- return ((partNum & wholeNum) != 0);
- }
-
-
-
-
-
-
- public static bool Equals(this Enum value, Enum target)
- {
-
-
-
-
- ulong valueNum = Convert.ToUInt64(value);
- ulong wholeNum = Convert.ToUInt64(target);
- return (valueNum == wholeNum);
- }
-
-
-
-
-
-
- public static bool SameType(Enum a, Enum b)
- {
- return (a.GetType() == b.GetType());
- }
- }
- }
|