25 lines
654 B
C#
25 lines
654 B
C#
using Newtonsoft.Json;
|
|
|
|
namespace Marco.Pms.Utility
|
|
{
|
|
public static class ParentToChildClassMapper
|
|
{
|
|
public static string ConvertToJson<T>(this T obj)
|
|
{
|
|
return JsonConvert.SerializeObject(obj);
|
|
}
|
|
public static T ConvertToObject<T>(this string json)
|
|
{
|
|
if (string.IsNullOrEmpty(json))
|
|
{
|
|
return Activator.CreateInstance<T>();
|
|
}
|
|
var result = JsonConvert.DeserializeObject<T>(json);
|
|
if (result == null) {
|
|
return Activator.CreateInstance<T>();
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|