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{
10 public sealed class FlagRightsConditional<TRights> : RightsConditional<TRights>
11 where TRights : Enum
12 {
16 readonly TRights flag;
17
23 {
24 var asUlong = (ulong)(object)flag;
25
26 if (asUlong == 0)
27 throw new ArgumentOutOfRangeException(nameof(flag), flag, "Flag cannot be zero!");
28
29 // https://stackoverflow.com/a/28303898/3976486
30 if ((asUlong & (asUlong - 1)) != 0)
31 throw new ArgumentException("Right has more than one bit set!", nameof(flag));
32
33 this.flag = flag;
34 }
35
37 public override bool Evaluate(TRights rights)
38 => rights.HasFlag(flag);
39
41 public override string ToString()
42 => $"{typeof(TRights).Name}.{flag}";
43 }
44}
FlagRightsConditional(TRights flag)
Initializes a new instance of the FlagRightsConditional<TRights> class.