-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
772 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// DupeNukem - WebView attachable full-duplex asynchronous interoperable | ||
// independent messaging library between .NET and JavaScript. | ||
// | ||
// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud) | ||
// | ||
// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0 | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace DupeNukem.Internal; | ||
|
||
internal sealed class JsonTokenConverter : JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) => | ||
typeof(JsonToken).IsAssignableFrom(objectType); | ||
|
||
public override object? ReadJson( | ||
JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) | ||
{ | ||
ConverterContext.AssertValidState(); | ||
|
||
if (serializer.Deserialize<JToken>(reader) is { } token) | ||
{ | ||
return JsonToken.FromJToken(ConverterContext.Current, token); | ||
} | ||
return null; | ||
} | ||
|
||
public override void WriteJson( | ||
JsonWriter writer, object? value, JsonSerializer serializer) | ||
{ | ||
ConverterContext.AssertValidState(); | ||
|
||
if (value is JsonToken t) | ||
{ | ||
serializer.Serialize(writer, t.token); | ||
} | ||
else | ||
{ | ||
writer.WriteNull(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.