protodec/LibProtodec/Enum.cs

39 lines
916 B
C#
Raw Normal View History

2023-04-24 04:10:40 +00:00
using System.CodeDom.Compiler;
using System.Collections.Generic;
namespace LibProtodec;
2023-04-24 04:10:40 +00:00
public sealed class Enum : Protobuf
2023-04-24 04:10:40 +00:00
{
public readonly List<KeyValuePair<int, string>> Fields = new();
2023-04-24 04:10:40 +00:00
public override void WriteFileTo(IndentedTextWriter writer)
2023-04-24 04:10:40 +00:00
{
this.WritePreambleTo(writer);
2023-04-24 04:10:40 +00:00
WriteTo(writer);
}
public override void WriteTo(IndentedTextWriter writer)
2023-04-24 04:10:40 +00:00
{
writer.Write("enum ");
writer.Write(this.Name);
2023-04-24 04:10:40 +00:00
writer.WriteLine(" {");
writer.Indent++;
if (Fields.ContainsDuplicateKey())
{
writer.WriteLine("""option allow_alias = true;""");
}
2023-04-24 04:10:40 +00:00
foreach ((int id, string name) in Fields)
{
writer.Write(name);
writer.Write(" = ");
writer.Write(id);
writer.WriteLine(';');
}
writer.Indent--;
writer.Write('}');
}
}