/// <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); }
/// <summary> /// Retrieves the descriptor for the field with the given name. /// </summary> /// <param name="name">Name of the field to retrieve the descriptor for</param> /// <returns>The descriptor for the given field</returns> /// <exception cref="KeyNotFoundException">The message descriptor does not contain a field /// with the given name</exception> public FieldDescriptor this[string name] { get { var fieldDescriptor = messageDescriptor.FindFieldByName(name); if (fieldDescriptor == null) { throw new KeyNotFoundException("No such field name"); } return(fieldDescriptor); } }