Ejemplo n.º 1
0
        internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file,
                                 MessageDescriptor parent, int index, string propertyName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            Proto = proto;
            if (proto.Type != 0)
            {
                fieldType = GetFieldTypeFromProtoType(proto.Type);
            }

            if (FieldNumber <= 0)
            {
                throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
            }
            ContainingType = parent;
            // OneofIndex "defaults" to -1 due to a hack in FieldDescriptor.OnConstruction.
            if (proto.OneofIndex != -1)
            {
                if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count)
                {
                    throw new DescriptorValidationException(this,
                                                            $"FieldDescriptorProto.oneof_index is out of range for type {parent.Name}");
                }
                ContainingOneof = parent.Oneofs[proto.OneofIndex];
            }

            file.DescriptorPool.AddSymbol(this);
            // We can't create the accessor until we've cross-linked, unfortunately, as we
            // may not know whether the type of the field is a map or not. Remember the property name
            // for later.
            // We could trust the generated code and check whether the type of the property is
            // a MapField, but that feels a tad nasty.
            this.propertyName = propertyName;
            JsonName          = Proto.JsonName == "" ? JsonFormatter.ToCamelCase(Proto.Name) : Proto.JsonName;
        }
Ejemplo n.º 2
0
        internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string propertyName) : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            while (true)
            {
IL_192:
                uint arg_155_0 = 668326049u;
                while (true)
                {
                    uint num;
                    switch ((num = (arg_155_0 ^ 1907900556u)) % 12u)
                    {
                    case 0u:
                        this.containingOneof = parent.Oneofs[proto.OneofIndex];
                        arg_155_0            = 951252349u;
                        continue;

                    case 2u:
                        goto IL_192;

                    case 3u:
                        arg_155_0 = (((proto.OneofIndex != -1) ? 3178787542u : 4269045895u) ^ num * 287148678u);
                        continue;

                    case 4u:
                        arg_155_0 = (((proto.OneofIndex < 0) ? 830153714u : 1120517676u) ^ num * 2667568972u);
                        continue;

                    case 5u:
                        this.proto = proto;
                        arg_155_0  = (((proto.Type == (FieldDescriptorProto.Types.Type) 0) ? 1249293554u : 878441721u) ^ num * 64997452u);
                        continue;

                    case 6u:
                        arg_155_0 = ((this.FieldNumber > 0) ? 416220771u : 1243880467u);
                        continue;

                    case 7u:
                        goto IL_199;

                    case 8u:
                        arg_155_0 = (((proto.OneofIndex < parent.Proto.OneofDecl.Count) ? 3890232560u : 2326943442u) ^ num * 1872585197u);
                        continue;

                    case 9u:
                        this.fieldType = FieldDescriptor.GetFieldTypeFromProtoType(proto.Type);
                        arg_155_0      = (num * 2182631442u ^ 3138733388u);
                        continue;

                    case 10u:
                        goto IL_1AA;

                    case 11u:
                        this.containingType = parent;
                        arg_155_0           = 1386389043u;
                        continue;
                    }
                    goto Block_6;
                }
            }
Block_6:
            goto IL_1CF;
IL_199:
            throw new DescriptorValidationException(this, Module.smethod_33 <string>(1349002182u));
IL_1AA:
            throw new DescriptorValidationException(this, FieldDescriptor.smethod_0(Module.smethod_37 <string>(3181016348u), new object[]
            {
                parent.Name
            }));
IL_1CF:
            file.DescriptorPool.AddSymbol(this);
            this.propertyName = propertyName;
        }