39 lines
874 B
C#
39 lines
874 B
C#
|
namespace Rizu.Core;
|
|||
|
|
|||
|
/*
|
|||
|
* JsonShim creates a single place that JSON APIs get called from, to avoid having to manually write precompiler directives every time.
|
|||
|
* Never call a JSON package directly, always call via JsonShim.
|
|||
|
*/
|
|||
|
|
|||
|
#if MONOMOD
|
|||
|
using UnityEngine;
|
|||
|
using System;
|
|||
|
#else
|
|||
|
using System.Text.Json;
|
|||
|
#endif
|
|||
|
|
|||
|
public class JsonShim
|
|||
|
{
|
|||
|
public static string Serialize(object Target)
|
|||
|
{
|
|||
|
#if MONOMOD
|
|||
|
return JsonUtility.ToJson(Target);
|
|||
|
#else
|
|||
|
return JsonSerializer.Serialize(Target);
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
public static T Deserialize<T>(string data)
|
|||
|
{
|
|||
|
#if MONOMOD
|
|||
|
return JsonUtility.FromJson<T>(data);
|
|||
|
#else
|
|||
|
return JsonSerializer.Deserialize<T>(data);
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#if MONOMOD
|
|||
|
[AttributeUsage(AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple = false)]
|
|||
|
public class JsonIncludeAttribute : Attribute { }
|
|||
|
#endif
|