-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] Move devtools generator to System.Text.Json, update to .NET 8
#15061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
52bb736
[dotnet] Move devtools generator to System.Text.Json, update to .NET 8
RenderMichael fb89a79
Remove newline
RenderMichael f6c5d80
add `#nullable` to bazel
RenderMichael 8fcb5f3
Merge branch 'devtools-json' of https://github.com/RenderMichael/sele…
RenderMichael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
6 changes: 3 additions & 3 deletions
6
third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| namespace OpenQA.Selenium.DevToolsGenerator.CodeGen | ||
| { | ||
| using Newtonsoft.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| /// <summary> | ||
| /// Defines settings around templates | ||
| /// </summary> | ||
| public class CodeGenerationTemplateSettings | ||
| { | ||
| [JsonProperty("templatePath")] | ||
| [JsonPropertyName("templatePath")] | ||
| public string TemplatePath { get; set; } | ||
|
|
||
| [JsonProperty("outputPath")] | ||
| [JsonPropertyName("outputPath")] | ||
| public string OutputPath { get; set; } | ||
| } | ||
| } |
87 changes: 39 additions & 48 deletions
87
third_party/dotnet/devtools/src/generator/Converters/BooleanJsonConverter.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,68 +1,59 @@ | ||
| namespace OpenQA.Selenium.DevToolsGenerator.Converters | ||
| { | ||
| using Newtonsoft.Json; | ||
| using System; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| /// <summary> | ||
| /// Handles converting JSON string values into a C# boolean data type. | ||
| /// </summary> | ||
| public class BooleanJsonConverter : JsonConverter | ||
| public class BooleanJsonConverter : JsonConverter<bool> | ||
| { | ||
| /// <summary> | ||
| /// Determines whether this instance can convert the specified object type. | ||
| /// </summary> | ||
| /// <param name="objectType">Type of the object.</param> | ||
| /// <returns> | ||
| /// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>. | ||
| /// </returns> | ||
| public override bool CanConvert(Type objectType) | ||
| { | ||
| // Handle only boolean types. | ||
| return objectType == typeof(bool); | ||
| } | ||
| public override bool HandleNull => false; | ||
|
|
||
| /// <summary> | ||
| /// Reads the JSON representation of the object. | ||
| /// </summary> | ||
| /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param> | ||
| /// <param name="objectType">Type of the object.</param> | ||
| /// <param name="existingValue">The existing value of object being read.</param> | ||
| /// <param name="serializer">The calling serializer.</param> | ||
| /// <returns> | ||
| /// The object value. | ||
| /// </returns> | ||
| public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
| public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| switch (reader.Value.ToString().ToLower().Trim()) | ||
| switch (reader.TokenType) | ||
| { | ||
| case "true": | ||
| case "yes": | ||
| case "y": | ||
| case "1": | ||
| case JsonTokenType.True: | ||
| return true; | ||
| case "false": | ||
| case "no": | ||
| case "n": | ||
| case "0": | ||
|
|
||
| case JsonTokenType.False: | ||
| return false; | ||
| } | ||
|
|
||
| // If we reach here, we're pretty much going to throw an error so let's let Json.NET throw it's pretty-fied error message. | ||
| return new JsonSerializer().Deserialize(reader, objectType); | ||
| } | ||
| case JsonTokenType.String: | ||
| string boolString = reader.GetString()!; | ||
| if (bool.TryParse(boolString, out bool b)) | ||
| { | ||
| return b; | ||
| } | ||
|
|
||
| boolString = boolString.ToLowerInvariant(); | ||
|
|
||
| /// <summary> | ||
| /// Specifies that this converter will not participate in writing results. | ||
| /// </summary> | ||
| public override bool CanWrite => false; | ||
| if (boolString.AsSpan().Trim().SequenceEqual("yes".AsSpan()) || | ||
| boolString.AsSpan().Trim().SequenceEqual("y".AsSpan()) || | ||
| boolString.AsSpan().Trim().SequenceEqual("1".AsSpan())) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (boolString.AsSpan().Trim().SequenceEqual("no".AsSpan()) || | ||
| boolString.AsSpan().Trim().SequenceEqual("n".AsSpan()) || | ||
| boolString.AsSpan().Trim().SequenceEqual("0".AsSpan())) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| throw new JsonException(); | ||
|
|
||
| default: | ||
| throw new JsonException(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes the JSON representation of the object. | ||
| /// </summary> | ||
| /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param><param name="value">The value.</param><param name="serializer">The calling serializer.</param> | ||
| public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
| public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) | ||
| { | ||
| throw new NotSupportedException(); | ||
| writer.WriteBooleanValue(value); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.