mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
Util method to cache a Type for JSON serialization
This commit is contained in:
@@ -29,8 +29,16 @@ namespace ICD.Common.Utils.Json
|
||||
public static void CacheType<T>()
|
||||
where T : new()
|
||||
{
|
||||
string serialized = JsonConvert.SerializeObject(ReflectionUtils.CreateInstance<T>());
|
||||
JsonConvert.DeserializeObject<T>(serialized);
|
||||
CacheType(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forces Newtonsoft to cache the given type for faster subsequent usage.
|
||||
/// </summary>
|
||||
public static void CacheType(Type type)
|
||||
{
|
||||
string serialized = JsonConvert.SerializeObject(ReflectionUtils.CreateInstance(type));
|
||||
JsonConvert.DeserializeObject(serialized, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user