tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
FlagRightsConditional{TRights}.cs
Go to the documentation of this file.
1using System;
2
4{
9 public sealed class FlagRightsConditional<TRights> : RightsConditional<TRights>
10 where TRights : Enum
11 {
15 readonly TRights flag;
16
22 {
23 var asUlong = (ulong)(object)flag;
24
25 if (asUlong == 0)
26 throw new ArgumentOutOfRangeException(nameof(flag), flag, "Flag cannot be zero!");
27
28 // https://stackoverflow.com/a/28303898/3976486
29 if ((asUlong & (asUlong - 1)) != 0)
30 throw new ArgumentException("Right has more than one bit set!", nameof(flag));
31
32 this.flag = flag;
33 }
34
36 public override bool Evaluate(TRights rights)
37 => rights.HasFlag(flag);
38
40 public override string ToString()
41 => $"{typeof(TRights).Name}.{flag}";
42 }
43}
FlagRightsConditional(TRights flag)
Initializes a new instance of the FlagRightsConditional<TRights> class.