27 lines
635 B
C#
27 lines
635 B
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
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>();
|
|
}
|
|
return JsonConvert.DeserializeObject<T>(json);
|
|
|
|
}
|
|
}
|
|
}
|