mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +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 ICD.Common.Properties;
|
||||
using ICD.Common.Utils.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ICD.Common.Utils.Json
|
||||
{
|
||||
@@ -11,6 +12,17 @@ namespace ICD.Common.Utils.Json
|
||||
[PublicAPI]
|
||||
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>
|
||||
/// Pretty-prints the JSON document.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user