public class LazyJsonizer<T>
{
T Value;
public LazyJsonizer(T value)
{
Value = value;
}
override public string ToString()
{
return LazyJsonizer.Instance.Format(null, Value, null);
}
}
public class LazyJsonizer : IFormatProvider, ICustomFormatter
{
static public readonly LazyJsonizer Instance = new LazyJsonizer();
static public LazyJsonizer<T> Create<T>(T value)
{
return new LazyJsonizer<T>(value);
}
public object GetFormat(Type formatType)
{
return this;
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
try
{
return JsonConvert.SerializeObject(arg);
}
catch (Exception ex)
{
return ex.Message;
}
}
}
DOT NET
Kasani007, if this helps please login to Mark As Answer. | Alert Moderator