示例#1
0
        private static void GenerateFlagsValidationMethodBody(GeneratorExecutionContext context, StringBuilder sb, EnumValidationInfo info, string indent)
        {
            int total = 0;

            foreach (int value in info.Values)
            {
                total |= value;
            }
            sb.AppendLine($"{indent}if ((intValue & {total}) == intValue) return;");
        }
示例#2
0
 private static void GenerateSequenceValidationMethodBody(GeneratorExecutionContext context, StringBuilder sb, EnumValidationInfo info, string indent)
 {
     foreach ((int min, int max) in GetElementSets(context, info.Values))
     {
         if (min == max)
         {
             sb.AppendLine($"{indent}if (intValue == {min}) return;");
         }
         else
         {
             sb.AppendLine($"{indent}if (intValue >= {min} && intValue <= {max}) return;");
         }
     }
 }
示例#3
0
 private static void GenerateValidateMethodBody(GeneratorExecutionContext context, StringBuilder sb, EnumValidationInfo info, string indent)
 {
     sb.AppendLine($"{indent}int intValue = (int)enumToValidate;");
     if (info.IsFlags)
     {
         GenerateFlagsValidationMethodBody(context, sb, info, indent);
     }
     else
     {
         GenerateSequenceValidationMethodBody(context, sb, info, indent);
     }
     sb.AppendLine($"{indent}ReportEnumValidationError(parameterName, intValue, typeof({info.EnumType}));");
 }