{"record":{"id":"431bfa7186d12376","repo":"peass-ng/PEASS-ng","slug":"value","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs","lineNumber":32,"sourceCode":"                throw new ArgumentException($\"Type '{typeof(T).FullName}' doesn't have the 'Flags' attribute\");\n        }\n\n        public static bool IsFlags<T>() => Attribute.IsDefined(typeof(T), typeof(FlagsAttribute));\n\n        public static void CheckHasValue<T>(T value, string argName = null)\n        {\n            CheckIsEnum<T>();\n            if (IsFlags<T>())\n            {\n                var allFlags = 0L;\n                foreach (T flag in Enum.GetValues(typeof(T)))\n                    allFlags |= Convert.ToInt64(flag);\n                if ((allFlags & Convert.ToInt64(value)) != 0L)\n                    return;\n            }\n            else if (Enum.IsDefined(typeof(T), value))\n                return;\n            throw new InvalidEnumArgumentException(argName ?? \"value\", Convert.ToInt32(value), typeof(T));\n        }\n\n        public static byte BitPosition<T>(this T flags) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var flagValue = Convert.ToInt64(flags);\n            if (flagValue == 0) throw new ArgumentException(\"The flag value is zero and has no bit position.\");\n            var r = Math.Log(flagValue, 2);\n            if (r % 1 > 0) throw new ArithmeticException(\"The flag value has more than a single bit set.\");\n            return Convert.ToByte(r);\n        }\n\n        public static bool IsFlagSet<T>(this T flags, T flag) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var flagValue = Convert.ToInt64(flag);\n            return (Convert.ToInt64(flags) & flagValue) == flagValue;\n        }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs#L14-L50","documentation":"CheckHasValue<T> validates that an enum argument holds a value defined by the enum (or, for flags enums, any combination of defined bits). On failure it throws InvalidEnumArgumentException naming the argument (default \"value\"), i.e. the message 'value' is the parameter name of the offending argument, not a description.","triggerScenarios":"Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass only values that are defined members of the enum type, or valid bitwise combinations for flags enums.","Cast to the enum type rather than passing raw ints so invalid values are caught earlier.","Validate with Enum.IsDefined (or a mask check for flags) before calling APIs that use CheckHasValue."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}