Example #1
0
        private void MyStruct_AddWithMethod(CsEnumItem enumItem, bool isFirst)
        {
            if (isFirst)
            {
                var          cw            = new CsCodeWriter();
                const string maskVariable  = "value";
                const string modifiedValue = "current";
                cw.SingleLineIf("add", $"return {modifiedValue} | {maskVariable};",
                                $"return {modifiedValue} & ~{maskVariable};");
                var m = ExtensionsClass
                        .AddMethod(SetOrClearMethod, MyEnumTypeName)
                        .WithBody(cw)
                        .WithStatic();
                m.AddAggressiveInlining(ExtensionsClass);
                m.AddParam(modifiedValue, MyEnumTypeName).UseThis = true;
                m.AddParam(maskVariable, MyEnumTypeName);
                m.AddParam("add", "bool");
            }

            {
                var mask = GetMask(MyEnum, enumItem.EnumName);
                var cw   = CsCodeWriter.Create <SingleTaskEnumsGenerator>();
                cw.WriteLine($"{flagsPropertyName} = {flagsPropertyName}.{SetOrClearMethod}({mask}, value);");
                cw.WriteLine("return this;");
                var m = MyStruct.AddMethod("With" + enumItem.EnumName, OptionsClassName)
                        .WithBody(cw);
                m.AddParam("value", "bool").ConstValue = "true";
                m.Description = enumItem.Description;
            }
        }