PrettyObject 1.0.0
See the version list below for details.
dotnet add package PrettyObject --version 1.0.0
NuGet\Install-Package PrettyObject -Version 1.0.0
<PackageReference Include="PrettyObject" Version="1.0.0" />
paket add PrettyObject --version 1.0.0
#r "nuget: PrettyObject, 1.0.0"
// Install PrettyObject as a Cake Addin #addin nuget:?package=PrettyObject&version=1.0.0 // Install PrettyObject as a Cake Tool #tool nuget:?package=PrettyObject&version=1.0.0
Pretty Object
Pretty Object is an object pretty-printer for handling Golden Master test output. Pretty Object, out of the box, will print all accessible fields in an object as a new-line delimited output. You can also provide transformations for any field values which either should be ignored, or might need to be modified, such as DateTime comparisons.
Usage
Just Printing Object Properties
Example with Approvals:
// Don't forget to add a using statement:
// using PrettyObject;
var testObject = new TestObject();
var objectFieldOutput = PrettyPrinter.PrettyPrint(testObject);
Approvals.Verify(objectFieldOutput);
It can also be used as a mixin:
// Don't forget to add a using statement:
// using PrettyObject;
var testObject = new TestObject();
Approvals.Verify(testObject.PrettyPrint(testObject));
Modifying Properties Before Printing
Using an anonymous object with field name and transformation funcs:
var testObject = new TestObject();
var verificationOutput = testObject.PrettyPrint(new
{
StringField = new Func<string, string>((value)
=> ReverseString(value)),
IntField = new Func<int, string>((value)
=> (value * 2).ToString())
});
Approvals.Verify(verificationOutput);
Using a single func (JavaScript JSON.stringify style transformations):
var testObject = new TestObject();
Func<string, object, string> transformStringValue = (name, value) =>
{
switch (name)
{
case "StringField":
return ReverseString(value);
default:
return value.ToNullSafeString();
}
};
var objectFieldOutput = testObject.PrettyPrint(transformStringValue);
Approvals.Verify(objectFieldOutput);
Public API
- PrettyPrint:
public string PrettyPrint(this T objectToPrint)
public string PrettyPrint(this T objectToPrint, Func<string, object, object> transformer)
public string PrettyPrint(this T objectToPrint, Func<string, object, string> transformer)
public string PrettyPrint(this T objectToPrint, object transformer)
- All properties for the transformer object must be
Func<T, string>
- All properties for the transformer object must be
- ToNullSafeString:
public string ToNullSafeString<T>(this T value)
- ToStringOrNull:
public string ToStringOrNull<T>(this T value)
Thanks and Contributors
Big thanks to @jason-kerney for his contributions!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial 1.0.0 release