public Field(ServiceDetails svc, MessageDescriptor msg, string fieldName)
                {
                    Descs = fieldName.Split('.').Aggregate((msg, result: ImmutableList <FieldDescriptor> .Empty), (acc, part) =>
                    {
                        // TODO: Check nested fields aren't repeated.
                        var fieldDesc = acc.msg.FindFieldByName(part);
                        if (fieldDesc == null)
                        {
                            throw new InvalidOperationException($"Field '{part}' does not exist in message: {acc.msg.FullName}");
                        }
                        return(fieldDesc.FieldType == FieldType.Message ? fieldDesc.MessageType : null, acc.result.Add(fieldDesc));
                    }, acc => acc.result);
                    var lastDesc = Descs.Last();

                    Typ            = ProtoTyp.Of(lastDesc);
                    IsMap          = lastDesc.IsMap;
                    IsRepeated     = lastDesc.IsRepeated;
                    IsWrapperType  = ProtoTyp.IsWrapperType(lastDesc);
                    IsRequired     = lastDesc.GetExtension(FieldBehaviorExtensions.FieldBehavior).Any(x => x == FieldBehavior.Required);
                    ParameterName  = lastDesc.CSharpFieldName();
                    PropertyName   = lastDesc.CSharpPropertyName();
                    IsDeprecated   = Descs.Any(x => x.IsDeprecated());
                    DocLines       = lastDesc.Declaration.DocLines();
                    FieldResources = svc.Catalog.GetResourceDetailsByField(lastDesc);
                }
        /// <summary>
        /// Finds an appropriate candidate for a `page size`/`max results` request field.
        /// That is a field that is named "page_size" or "max_results" and has a non-repeated Int32 type, if any.
        /// If no such field exists, then simply a field that is named "page_size" or "max_results".
        /// </summary>
        private static FieldDescriptor FindPageSizeCandidate(MessageDescriptor input)
        {
            // Has the int32 page_size or int32 max_results field which defines the maximum number of paginated resources to return in the response
            var pageSizeCandidate   = input.FindFieldByName("page_size");
            var maxResultsCandidate = input.FindFieldByName("max_results");

            // If both candidates are invalid, this might return a non-null 'invalid' candidate.
            // An exception should be thrown, but only if method has _all_ candidates, which we will only know later.
            return(IsValidPageSizeCandidate(pageSizeCandidate) ? pageSizeCandidate
                : IsValidPageSizeCandidate(maxResultsCandidate) ? maxResultsCandidate
                : pageSizeCandidate ?? maxResultsCandidate);
        }
Ejemplo n.º 3
0
        public static bool IsDefaultBase(this Google.Protobuf.Reflection.MessageDescriptor from)
        {
            if (from.Name.EndsWith("_nullable"))
            {
                return(false);
            }
            if (from.Name.EndsWith("_nullable_enum"))
            {
                return(false);
            }
            var doc = JsonDoc.Files[from.File.Name].Messages[from.Name];

            //Trace.TraceInformation("#############  Doc base class: " + doc.BaseClass);
            if (string.IsNullOrWhiteSpace(doc.BaseClass) ||
                doc.BaseClass.Contains("ConfigObjectVmBase") ||
                doc.BaseClass.Contains("ConfigObjectCommonBase") ||
                doc.BaseClass.Contains("ConfigObjectVmGenSettings")
                )
            {
                return(true);
            }
            return(false);
        }
 public Signature(ServiceDetails svc, MessageDescriptor msg, string sig)
 {
     Fields = sig.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(fieldName => new Field(svc, msg, fieldName.Trim())).ToList();
 }
Ejemplo n.º 5
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;
        }