public static string Dump(object data, EncodeOptions options) { // Invoke methods tagged with [BeforeEncode] attribute. if (data != null) { #if !NETCORE var type = data.GetType(); if (!(type.IsEnum || type.IsPrimitive || type.IsArray)) { foreach (var method in type.GetMethods(instanceBindingFlags)) { if (method.GetCustomAttributes(false).AnyOfType(typeof(BeforeEncodeAttribute))) { if (method.GetParameters().Length == 0) { method.Invoke(data, null); } } } } #else var dataType = data.GetType(); var type = dataType.GetTypeInfo(); if (!(type.IsEnum || type.IsPrimitive || type.IsArray)) { foreach (var method in dataType.GetMethods(instanceBindingFlags)) { if (method.GetCustomAttributes(false).AnyOfType(typeof(BeforeEncodeAttribute))) { if (method.GetParameters().Length == 0) { method.Invoke(data, null); } } } } #endif } return(Encoder.Encode(data, options)); }
public static string Dump(object data, bool prettyPrint = false) { return(Encoder.Encode(data, prettyPrint)); }
public string Dump(EncodeOptions options = EncodeOptions.Default) { return(Encoder.Encode(this, options)); }
/// <summary> /// Encodes the given object into a JSON string. /// </summary> public static string Encode(object data, EncodeOptions options = EncodeOptions.None) { return(Encoder.Encode(data, options)); }