Created
May 21, 2023 13:08
-
-
Save AndyButland/735d6bb0070e41e97a43def6231b4d65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void SelectFields(SearchOptions options, PackageSearchQuery query) | |
{ | |
SelectDefaultFields(options); | |
if (!query.Fields.Any()) | |
{ | |
return; | |
} | |
foreach (var field in query.Fields) | |
{ | |
var fieldName = field.CamelCaseToPascalCase(); | |
PropertyInfo? property = typeof(PackageModel).GetProperty(fieldName); | |
if (property == null) | |
{ | |
continue; | |
} | |
if (options.Select.Contains(fieldName)) | |
{ | |
continue; | |
} | |
options.Select.Add(fieldName); | |
} | |
} | |
private static bool IsFieldRequested(string field, IList<string> fields, [NotNullWhen(true)] out string? requestedField) | |
{ | |
requestedField = fields.FirstOrDefault(x => string.Equals(field, x, StringComparison.OrdinalIgnoreCase)); | |
return requestedField != null; | |
} | |
private static void SelectDefaultFields(SearchOptions options) | |
{ | |
options.Select.Add(nameof(PackageModel.Id)); | |
options.Select.Add(nameof(PackageModel.PackageId)); | |
options.Select.Add(nameof(PackageModel.Title)); | |
options.Select.Add(nameof(PackageModel.LatestVersionNumber)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment