void WriteConstants(FileWriter writer, ConstantsType constantsType)
        {
            docWriter.WriteSummary(writer, constantsType.Documentation, constantsType.RawName);
            var pub = constantsType.IsPublic ? "public " : string.Empty;

            writer.WriteLine($"{pub}static class {constantsType.Name(idConverter)} {{");

            using (writer.Indent()) {
                foreach (var constant in constantsType.Constants)
                {
                    docWriter.WriteSummary(writer, constant.Documentation, constantsType.RawName);
                    deprecatedWriter.WriteDeprecated(writer, constant);
                    writer.Write(constant.IsPublic ? "public " : "internal ");
                    writer.Write("const ");
                    writer.Write(GetType(constant.Kind));
                    writer.Write(" ");
                    writer.Write(constant.Name(idConverter));
                    writer.Write(" = ");
                    writer.Write(GetValue(constant));
                    writer.WriteLine(";");
                }
            }

            writer.WriteLine("}");
        }
        void WriteConstants(FileWriter writer, ConstantsType constantsType, bool isPartialClass)
        {
            docWriter.WriteSummary(writer, constantsType.Documentation.GetComment(TargetLanguage.CSharp), constantsType.RawName);
            var pub     = constantsType.IsPublic ? "public " : string.Empty;
            var partial = isPartialClass ? " partial" : string.Empty;

            writer.WriteLine($"{pub}static{partial} class {constantsType.Name(idConverter)} {{");

            using (writer.Indent()) {
                foreach (var constant in constantsType.Constants)
                {
                    docWriter.WriteSummary(writer, constant.Documentation.GetComment(TargetLanguage.CSharp), constantsType.RawName);
                    deprecatedWriter.WriteDeprecated(writer, constant);
                    writer.Write(constant.IsPublic ? "public " : "internal ");
                    writer.Write("const ");
                    writer.Write(GetType(constant.Kind));
                    writer.Write(" ");
                    writer.Write(constant.Name(idConverter));
                    writer.Write(" = ");
                    writer.Write(GetValue(constant));
                    writer.WriteLine(";");
                }
            }

            writer.WriteLine("}");
        }
Exemple #3
0
        void WriteEnum(FileWriter writer, EnumType enumType, string?baseType)
        {
            if (enumType.IsPublic && enumType.IsMissingDocs)
            {
                writer.WriteLineNoIndent(CSharpConstants.PragmaMissingDocsDisable);
            }
            docWriter.WriteSummary(writer, enumType.Documentation, enumType.RawName);
            if (enumType.IsFlags)
            {
                writer.WriteLine("[Flags]");
            }
            var pub         = enumType.IsPublic ? "public " : string.Empty;
            var theBaseType = baseType is not null ? $" : {baseType}" : string.Empty;

            writer.WriteLine($"{pub}enum {enumType.Name(idConverter)}{theBaseType} {{");
            using (writer.Indent()) {
                uint expectedValue = 0;
                foreach (var value in enumType.Values)
                {
                    docWriter.WriteSummary(writer, value.Documentation, enumType.RawName);
                    deprecatedWriter.WriteDeprecated(writer, value);
                    if (enumType.IsFlags)
                    {
                        writer.WriteLine($"{value.Name(idConverter)} = 0x{value.Value:X8},");
                    }
                    else if (expectedValue != value.Value || enumType.IsPublic)
                    {
                        writer.WriteLine($"{value.Name(idConverter)} = {value.Value},");
                    }
                    else
                    {
                        writer.WriteLine($"{value.Name(idConverter)},");
                    }
                    expectedValue = value.Value + 1;
                }
            }
            writer.WriteLine("}");
            if (enumType.IsPublic && enumType.IsMissingDocs)
            {
                writer.WriteLineNoIndent(CSharpConstants.PragmaMissingDocsRestore);
            }
        }