TooString 0.1.0

dotnet add package TooString --version 0.1.0                
NuGet\Install-Package TooString -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TooString" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TooString --version 0.1.0                
#r "nuget: TooString, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TooString as a Cake Addin
#addin nuget:?package=TooString&version=0.1.0

// Install TooString as a Cake Tool
#tool nuget:?package=TooString&version=0.1.0                

The TooString() extension method stringifies objects in ways that other serializers don't.

TooString() can

  • make a best effort to stringify unserializable objects.
  • Output as Json, or C# Code, or ‘debug’ output

Example:

( Math.Sqrt(4 * Math.PI / 3)  ).TooString( TooStringStyle.CallerArgument ) 
// Output is the literal code: "Math.Sqrt(4 * Math.PI / 3)"

new { A = "boo", B = new Complex(3,4) }.TooString(TooStringStyle.Json);
// Output is the System.Text.Json output:
// {"A":"boo","B":{"Real":3,"Imaginary":4,"Magnitude":5,"Phase":0.9272952180016122}}

new { A = "boo", B = new Complex(3,4) }.TooString(TooStringStyle.Reflection);
// Output is "{ A = boo, B = { Real = 3, Imaginary = 4, Magnitude = 5, Phase = 0.9272952180016122 } }" 

Advanced usage

Example: Json-serializing value tuples is something of a surprise because (unlike anonymous objects or records or structs) they have no public properties and their public fields are not named as per your code. Takeaway: don't choose value tuples for public apis that must be jsonned.

Use modifications of TooStringOptions.Default to customise the results.

(one:1, two:"2").TooString( TooStringStyle.Json )
System.Text.Json.JsonSerializer.Serialize(  (one:1, two:"2")  )
// Output is "{}" because there are no public fields

// do this instead:

var options = TooStringOptions.Default with
{
    JsonOptions = new JsonSerializerOptions { IncludeFields = true }
};
var jsonnedIncludeFields = (one:1, two:"2") .TooString(options);
// Output is "{Item1:1,Item2:"2"}"

- Infinite loops are avoided with MaxDepth settings.

ChangeLog

0.1.0.0 Can use Reflection, Json, ToString() or [CallerArgumentExpression] and can output Json or Debug strings.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TooString:

Package Downloads
TestBase

*TestBase* gives you a flying start with - fluent assertions that are easy to extend - sharp error messages - tools to help you test with “heavyweight” dependencies on - AspNetCore.Mvc, AspNet.Mvc or WebApi Contexts - HttpClient - Ado.Net - Streams & Logging - Mix & match with your favourite test runners & assertions. ``` UnitUnderTest.Action() .ShouldNotBeNull() .ShouldEqualByValueExceptFor(new {Id=1, Descr=expected}, ignoreList ) .Payload .ShouldMatchIgnoringCase("I expected this") .Should(someOtherPredicate); .Items .ShouldAll(predicate) .ShouldContain(item) .ShouldNotContain(predicate) .Where(predicate) .SingleOrAssertFail() .ShouldEqualByValue().ShouldEqualByValueExceptFor(...).ShouldEqualByValueOnMembers() work with all kinds of object and collections, and report what differed. string.ShouldMatch(pattern).ShouldNotMatch().ShouldBeEmpty().ShouldNotBeEmpty() .ShouldNotBeNullOrEmptyOrWhiteSpace().ShouldEqualIgnoringCase() .ShouldContain().ShouldStartWith().ShouldEndWith().ShouldBeContainedIn(), ... numeric.ShouldBeBetween().ShouldEqualWithTolerance()....GreaterThan....LessThan...GreaterOrEqualTo ... ienumerable.ShouldAll().ShouldContain().ShouldNotContain().ShouldBeEmpty().ShouldNotBeEmpty() ... stream.ShouldHaveSameStreamContentAs().ShouldContain() value.ShouldBe().ShouldNotBe().ShouldBeOfType().ShouldBeAssignableTo()... ``` Testable Logging is in packages Extensions.Logging.ListOfString and Serilog.Sinks.ListOfString ``` // Extensions.Logging.ListOfString var log = new List<String>(); ILogger mslogger= new LoggerFactory().AddStringListLogger(log).CreateLogger("Test2"); // Serilog.Sinks.ListOfString Serilog.Logger slogger= new LoggerConfiguration().WriteTo.StringList(log).CreateLogger(); ```

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0 96 7/11/2024

ChangeLog
           ---------
           0.1.0.0  Can use Reflection, Json, ToString() or [CallerArgumentExpression] and can output Json or Debug strings.