コード例 #1
0
ファイル: OneofDescriptor.cs プロジェクト: 2php/protobuf
        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);
        }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file,
                                 MessageDescriptor parent, int index)
        {
            this.proto = proto;
            this.file  = file;
            this.index = index;

            containingType = parent;
            fieldCount     = 0;
        }
コード例 #5
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file,
                                 MessageDescriptor parent, int index)
        {
            this.proto = proto;
            this.file = file;
            this.index = index;

            containingType = parent;
            fieldCount = 0;
        }
コード例 #6
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);
        }
コード例 #7
0
        /// <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("}");
            }
        }
コード例 #8
0
 /// <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();
 }
コード例 #9
0
 /// <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,");
 }
コード例 #10
0
 private static string GetOneOfFieldName(OneofDescriptorProto obj) => FieldPrefix + obj.Name;
コード例 #11
0
 internal OneOfStub(OneofDescriptorProto decl)
 {
     OneOf = decl;
 }
コード例 #12
0
 internal OneOfStub(OneofDescriptorProto decl, int index)
 {
     OneOf = decl;
     Index = index;
 }
コード例 #13
0
 /// <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;
 }
コード例 #14
0
 /// <summary>
 /// Emit  the discriminator accessor for 'oneof' groups
 /// </summary>
 protected virtual void WriteOneOfDiscriminator(GeneratorContext ctx, OneofDescriptorProto obj, ref object state)
 {
 }
コード例 #15
0
 /// <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");
 }