This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from zkxs/basex-types
Add built-in configuration support for basic BaseX types
- Loading branch information
Showing
2 changed files
with
55 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using BaseX; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace NeosModLoader.JsonConverters | ||
{ | ||
class NeosPrimitiveConverter : JsonConverter | ||
{ | ||
private static readonly Assembly BASEX = typeof(color).Assembly; | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return BASEX.Equals(objectType.Assembly) && Coder.IsNeosPrimitive(objectType); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
string serialized = (string)reader.Value; | ||
return typeof(Coder<>).MakeGenericType(objectType).GetMethod("DecodeFromString").Invoke(null, new object[] { serialized }); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
string serialized = (string)typeof(Coder<>).MakeGenericType(value.GetType()).GetMethod("EncodeToString").Invoke(null, new object[] { value }); | ||
writer.WriteValue(serialized); | ||
} | ||
} | ||
} |
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