mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 05:05:05 +00:00
Moving util method for caching a type with Newtonsoft JSON
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.Extensions;
|
using ICD.Common.Utils.Extensions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Json
|
namespace ICD.Common.Utils.Json
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,17 @@ namespace ICD.Common.Utils.Json
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static class JsonUtils
|
public static class JsonUtils
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Forces Newtonsoft to cache the given type for faster subsequent usage.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public static void CacheType<T>()
|
||||||
|
where T : new()
|
||||||
|
{
|
||||||
|
string serialized = JsonConvert.SerializeObject(ReflectionUtils.CreateInstance<T>());
|
||||||
|
JsonConvert.DeserializeObject<T>(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pretty-prints the JSON document.
|
/// Pretty-prints the JSON document.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user