-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter out invalid requirement strings from array
- Loading branch information
Showing
4 changed files
with
94 additions
and
26 deletions.
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementArrayConverter.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Immutable; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace NuGetUpdater.Core.Analyze; | ||
|
||
public class RequirementArrayConverter : JsonConverter<ImmutableArray<Requirement>> | ||
{ | ||
public override ImmutableArray<Requirement> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var requirements = new List<Requirement>(); | ||
var requirementStrings = JsonSerializer.Deserialize<string[]>(ref reader, options) ?? []; | ||
foreach (var requirementString in requirementStrings) | ||
{ | ||
try | ||
{ | ||
var requirement = Requirement.Parse(requirementString); | ||
requirements.Add(requirement); | ||
} | ||
catch (ArgumentException) | ||
{ | ||
// couldn't parse, nothing to do | ||
} | ||
} | ||
|
||
return requirements.ToImmutableArray(); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, ImmutableArray<Requirement> value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartArray(); | ||
foreach (var requirement in value) | ||
{ | ||
writer.WriteStringValue(requirement.ToString()); | ||
} | ||
|
||
writer.WriteEndArray(); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementConverter.cs
This file was deleted.
Oops, something went wrong.