public static string SerializeToString(object value, Type type) { if (value == null) { return(null); } var writer = StringWriterThreadStatic.Allocate(); if (type == typeof(string)) { JsonUtils.WriteString(writer, value as string); } else { JsonWriter.GetWriteFn(type)(writer, value); } return(StringWriterThreadStatic.ReturnAndFree(writer)); }
public static string SerializeToString <T>(T value) { if (value == null || value is Delegate) { return(null); } if (typeof(T) == typeof(object)) { return(SerializeToString(value, value.GetType())); } if (typeof(T).IsAbstract || typeof(T).IsInterface) { JsState.IsWritingDynamic = true; var result = SerializeToString(value, value.GetType()); JsState.IsWritingDynamic = false; return(result); } var writer = StringWriterThreadStatic.Allocate(); JsvWriter <T> .WriteRootObject(writer, value); return(StringWriterThreadStatic.ReturnAndFree(writer)); }