internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName) : base(file, file.ComputeFullName(parent, proto.Name), index) { this.proto = proto; containingType = parent; file.DescriptorPool.AddSymbol(this); accessor = CreateAccessor(clrName); }
/// <summary> /// Emit the discriminator accessor for 'oneof' groups /// </summary> protected override void WriteOneOfDiscriminator(GeneratorContext ctx, OneofDescriptorProto oneof, ref object state) { var name = ctx.NameNormalizer.GetName(oneof); var fieldName = GetOneOfFieldName(oneof); ctx.WriteLine($"Public ReadOnly Property {name}{OneOfEnumSuffixDiscriminator} As {name}{OneOfEnumSuffixEnum}").Indent().WriteLine("Get").Indent() .WriteLine($"Return {fieldName}.Discriminator") .Outdent().WriteLine("End Get").Outdent().WriteLine("End Property").WriteLine(); }
/// <summary> /// Suggest a normalized identifier /// </summary> public virtual string GetName(OneofDescriptorProto definition) { var name = definition?.Options?.GetOptions()?.Name; if (!string.IsNullOrWhiteSpace(name)) { return(name); } return(GetName(definition.Parent as DescriptorProto, GetName(definition.Name), definition.Name, false)); }
internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index) { this.proto = proto; this.file = file; this.index = index; containingType = parent; fieldCount = 0; }
internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName) : base(file, file.ComputeFullName(parent, proto.Name), index) { this.proto = proto; containingType = parent; file.DescriptorPool.AddSymbol(this); // It's useful to determine whether or not this is a synthetic oneof before cross-linking. That means // diving into the proto directly rather than using FieldDescriptor, but that's okay. var firstFieldInOneof = parent.Proto.Field.FirstOrDefault(fieldProto => fieldProto.HasOneofIndex && fieldProto.OneofIndex == index); IsSynthetic = firstFieldInOneof?.Proto3Optional ?? false; accessor = CreateAccessor(clrName); }
/// <summary> /// Emit the discriminator accessor for 'oneof' groups /// </summary> protected override void WriteOneOfDiscriminator(GeneratorContext ctx, OneofDescriptorProto oneof, ref object state) { var name = ctx.NameNormalizer.GetName(oneof); var fieldName = GetOneOfFieldName(oneof); if (ctx.Supports(CSharp6)) { ctx.WriteLine($"public {name}{OneOfEnumSuffixEnum} {name}{OneOfEnumSuffixDiscriminator} => ({name}{OneOfEnumSuffixEnum}){fieldName}.Discriminator;"); } else { ctx.WriteLine($"public {name}{OneOfEnumSuffixEnum} {name}{OneOfEnumSuffixDiscriminator}").WriteLine("{").Indent() .WriteLine($"get {{ return ({name}{OneOfEnumSuffixEnum}){fieldName}.Discriminator; }}") .Outdent().WriteLine("}"); } }
/// <summary> /// Emit the end of an enum declaration for 'oneof' groups /// </summary> protected override void WriteOneOfEnumFooter(GeneratorContext ctx, OneofDescriptorProto oneof, ref object state) { ctx.Outdent().WriteLine("}").WriteLine(); }
/// <summary> /// Emit the start of an enum declaration for 'oneof' groups, including the 0/None element /// </summary> protected override void WriteOneOfEnumHeader(GeneratorContext ctx, OneofDescriptorProto oneof, ref object state) { ctx.WriteLine().WriteLine($"public enum {ctx.NameNormalizer.GetName(oneof)}{OneOfEnumSuffixEnum}").WriteLine("{").Indent().WriteLine("None = 0,"); }
private static string GetOneOfFieldName(OneofDescriptorProto obj) => FieldPrefix + obj.Name;
internal OneOfStub(OneofDescriptorProto decl) { OneOf = decl; }
internal OneOfStub(OneofDescriptorProto decl, int index) { OneOf = decl; Index = index; }
/// <summary> /// Constructs Delphi source code representing a protobuf oneof. /// </summary> /// <param name="oneof">Protobuf oneof to generate code for</param> /// <param name="fields">Protobuf fields that are part of the oneof</param> public OneofSourceCode(OneofDescriptorProto oneof, IEnumerable <FieldSourceCode> fields) { this.oneof = oneof; Fields = fields; }
/// <summary> /// Emit the discriminator accessor for 'oneof' groups /// </summary> protected virtual void WriteOneOfDiscriminator(GeneratorContext ctx, OneofDescriptorProto obj, ref object state) { }
/// <summary> /// Emit the start of an enum declaration for 'oneof' groups, including the 0/None element /// </summary> protected override void WriteOneOfEnumHeader(GeneratorContext ctx, OneofDescriptorProto obj, ref object state) { ctx.WriteLine($"Public Enum {Escape(ctx.NameNormalizer.GetName(obj))}{OneOfEnumSuffixEnum}").Indent().WriteLine("None = 0"); }