DisplayHelper 1.3.0

Methods to simplify the display of objects and text, for Console and Windows Forms applications.

Install-Package DisplayHelper -Version 1.3.0
dotnet add package DisplayHelper --version 1.3.0
<PackageReference Include="DisplayHelper" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DisplayHelper --version 1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

DisplayHelper

DisplayHelper is a small .NET library designed to simplify the display of objects and text. Currently it can be used as-is with console applications and Windows Forms applications. However, it is relatively straight-forward to extend the base DisplayHelper class for use in other applications.

The DisplayHelper library targets .NET 2.0 to make it as broadly usable as possible.

Functionality Provided by DisplayHelper

Displaying Objects

The DisplayHelper uses reflection to display the values of an object's properties and fields. It will recurse down through the object graph, displaying the values of sub-properties (properties of objects that are properties of other objects), sub-sub-properties, etc.

The DisplayHelper has two mechanisms to prevent endless recursion:

  1. It will not follow direct or indirect circular references (for example, if a parent object has a Child property that has a Parent property pointing back to the original parent object). Instead it displays a message it has encountered a circular reference and skip the property involved, continuing to display details of other properties;

  2. It tracks how deep the recursion gets. It currently has a hard-coded maximum recursion depth of 5: If the same type of object appears on 5 different levels within the object graph the DisplayHelper will terminate its walk through the graph. In that case a message will be displayed to inform the user the DisplayHelper is terminating without having viewed the whole object graph, and the reason for the early termination.

In addition to recursing down through an object's properties, the DisplayHelper can display the properties of lists or arrays of objects.

The DisplayHelper will display messages if an object or property is null, or if a collection has no elements.

Static properties and fields of an object are not displayed. This is because static members are not ordinarily accessible from an object; normally they are accessed from the class, not from an instance of that type.

Displaying Exceptions

The DisplayHelper will display the type of an exception and the exception message. It will recurse down through any inner exceptions, and inner-inner exceptions, etc, displaying the details of each.

Displaying Data Tables

The DisplayHelper will display the values in every cell of every row of a specified data table. It can handle empty data tables and data tables that are set to null.

Displaying XML and JSON Text

The DisplayHelper will add line breaks and indents when displaying XML and JSON text to make them more readable.

Displaying Text

The DisplayHelper has several helper methods for displaying text. These are most useful in Console applications, although they can be used in Windows Forms applications as well:

  • Display indented text, with the indent width specified;

  • Display headed text, with the text in the form Header: My text. The indent level of the text can be specified;

  • Display numbered text, of the form: 2) My text. The indent level of the text can be specified;

  • Display titles and sub-titles, where the text is underlined. The only difference between a title and sub-title is the style of the underline.

DisplayHelper

DisplayHelper is a small .NET library designed to simplify the display of objects and text. Currently it can be used as-is with console applications and Windows Forms applications. However, it is relatively straight-forward to extend the base DisplayHelper class for use in other applications.

The DisplayHelper library targets .NET 2.0 to make it as broadly usable as possible.

Functionality Provided by DisplayHelper

Displaying Objects

The DisplayHelper uses reflection to display the values of an object's properties and fields. It will recurse down through the object graph, displaying the values of sub-properties (properties of objects that are properties of other objects), sub-sub-properties, etc.

The DisplayHelper has two mechanisms to prevent endless recursion:

  1. It will not follow direct or indirect circular references (for example, if a parent object has a Child property that has a Parent property pointing back to the original parent object). Instead it displays a message it has encountered a circular reference and skip the property involved, continuing to display details of other properties;

  2. It tracks how deep the recursion gets. It currently has a hard-coded maximum recursion depth of 5: If the same type of object appears on 5 different levels within the object graph the DisplayHelper will terminate its walk through the graph. In that case a message will be displayed to inform the user the DisplayHelper is terminating without having viewed the whole object graph, and the reason for the early termination.

In addition to recursing down through an object's properties, the DisplayHelper can display the properties of lists or arrays of objects.

The DisplayHelper will display messages if an object or property is null, or if a collection has no elements.

Static properties and fields of an object are not displayed. This is because static members are not ordinarily accessible from an object; normally they are accessed from the class, not from an instance of that type.

Displaying Exceptions

The DisplayHelper will display the type of an exception and the exception message. It will recurse down through any inner exceptions, and inner-inner exceptions, etc, displaying the details of each.

Displaying Data Tables

The DisplayHelper will display the values in every cell of every row of a specified data table. It can handle empty data tables and data tables that are set to null.

Displaying XML and JSON Text

The DisplayHelper will add line breaks and indents when displaying XML and JSON text to make them more readable.

Displaying Text

The DisplayHelper has several helper methods for displaying text. These are most useful in Console applications, although they can be used in Windows Forms applications as well:

  • Display indented text, with the indent width specified;

  • Display headed text, with the text in the form Header: My text. The indent level of the text can be specified;

  • Display numbered text, of the form: 2) My text. The indent level of the text can be specified;

  • Display titles and sub-titles, where the text is underlined. The only difference between a title and sub-title is the style of the underline.

Release Notes

ShowObject: Break circular references to avoid endless loops.  Add overload with simpleDataTypesOnly parameter.

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.0 19 11/17/2019
1.2.1 382 2/3/2017
1.2.0 345 1/8/2017
1.1.0 451 9/2/2016
1.0.0 551 8/27/2016