Skip to content

Commit

Permalink
flags
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Feb 12, 2024
1 parent 59d9134 commit bce7847
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CSUtilities/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ public static T GetValueByName<T>(string name)
return Enum.GetValues(typeof(T)).Cast<T>().FirstOrDefault(o => o.ToString() == name);
}

/// <summary>
/// Adds a flag value to enum
/// </summary>
public static T AddFlag<T>(this T value, T flag)
where T : Enum
{
return (T)(object)((int)(object)value | (int)(object)flag);
}

/// <summary>
/// Removes the flag value from enum
/// </summary>
public static T RemoveFlag<T>(this T value, T flag)
where T : Enum
{
return (T)(object)((int)(object)value & ~(int)(object)flag);
}

/// <summary>
/// Gets a string value for a particular enum value.
/// </summary>
Expand Down

0 comments on commit bce7847

Please sign in to comment.