Sign in Sign up
nuget

TooString

TooString is a Stringifier that goes places serializers don't. TooString can - make a best effort to stringify objects that JsonSerializer won't, including System.Reflection classes and System.Type; or for which JsonSerializer returns empty output, such as ValueTuples. - Output as Json or C# object notation, or 'debug view' style, or [CallerArgumentExpression] TooString offers 5 extension method groups on Object: ```csharp value.ToCSharpString() value.ToJson(); value.ToSTJson() value.TooString(); value.ToCallerArgumentExpression(); ``` _TooString is not a serializer._ - TooString offers both maxDepth and maxEnumerableLength options for abbreviated output. - TooString defaults to maxDepth = 3, maxEnumerableLength = 9. - A serializer should be fail-fast: a Serializer should throw if it cannot deterministically serialize the input, but TooString will attempt to return a partial representation of the input if the input cannot be reliably serialized. Example: ``` var value = new { A = "boo", B = new Complex(3,4) }; value.ToCSharpString() // Output is { A = "boo", B = <3; 4> } depending on .Net version. value.ToJson(); // Output is JSON: {"A":"boo","B":[3,4]} value.ToSTJson(); // Output is System.Text.Json: {"A":"boo","B":{"Real":3,...}} ( Math.Sqrt(4 * Math.PI / 3) ).ToCallerArgumentExpression() // Output is the literal code: "Math.Sqrt(4 * Math.PI / 3)" var tuple = (one: 1, two: "2", three: new Complex(3,4)); System.Text.Json.JsonSerializer.Serialize(tuple) // Output is "{}" because there // are no public properties on a tuple tuple.ToJson() // Output stringifies the tuple and the Complex number as arrays // [1,"2",[3,4]] tuple.ToCSharpString() // Output is created by reflection and // on Net6.0 : (1, "2", (3,4)) // on Net8.0+: (1, "2", <3;4>) var type = value.GetType(); System.Text.Json.JsonSerializer.Serialize(type) // Throws NotSupportedException type.ToJson() // Outputs the type object, truncated to default MaxDepth = 3, MaxEnumerationLength = 9 ```

Activity

Latest release
3mo ago
Total releases
18
Cadence
~2 days
Last 12 months
13

Reach

Stars

Details

License
unknown
First release
Jul 11, 2024
Releases
Version Released
0.8.10 minor
0.8.10-preview pre
0.8.9-preview pre
0.8.8-preview pre
0.8.7-preview pre
0.8.6-preview pre
0.8.4-preview pre
0.8.3-preview pre
0.8.2-preview pre
0.8.1-preview pre
0.7.0-preview pre
0.6.0 minor
0.5.1-preview pre
0.5.0-preview pre
0.4.0-preview pre
0.3.0-preview pre
0.2.0-preview pre
0.1.0 initial