Skip to content
ConsoleMonster

API Reference

Class

ValueShaper

Namespace ConsoleMonster.Values
Assembly ConsoleMonster
Modifiers static

The one model of what a value is, shared by every view (tables, lists, cards, trees, JSON, the automatic view and the object comparison): whether it is a scalar, a record or a collection, which fields a record has, how a value is written inside a cell or a title, and how nested records flatten. A type is supported once here and works everywhere. Records are read through adapters in this order: adapters registered with , the built-in data adapters (dictionaries, data rows, XML elements, JSON objects and nodes, files and folders, dictionary entries), , then reflection over public properties when allows it. Shapers registered with or turn a value into another one first (for example an object into an ordered dictionary of the fields worth showing).

Inheritance

  • Object
  • ValueShaper

Methods

public static Object? Cell(Object? value, ShapeOptions? options = null, ShapeBudget? budget = null) #
Returns: Object?

The value a table cell holds for value: scalars stay typed (so presenters format numbers, dates and Booleans), secure strings and byte arrays become their safe text, collections, dictionaries and records become one line of text (see ValueShaper.Text), an empty collection a muted dash, a failed getter a warning marker.

Parameters

value System.Object? requiredposition: 0
The value.
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optionalposition: 2
The pass budget, or null.

Returns

A scalar, a string or a TableCell.

public static IReadOnlyList<InspectMember> Fields(Object record, ShapeOptions? options = null) #
Returns: IReadOnlyList<InspectMember>

The fields of a record, in display order: a Hashtable's keys sorted, other dictionaries in their own order, columns of a data row, attributes and child elements of an XML element, properties of an object. Plumbing members of objects (ValueShaper.IsPlumbing) are left out; dictionary keys and data columns are data and always kept.

Parameters

record System.Object requiredposition: 0
The record (prepared).
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.

Returns

The fields (values are read lazily), or an empty list when the value is not a record.

public static IMemberSource? FindAdapter(Object value, ShapeOptions options) #
Returns: IMemberSource?

The adapter that reads a record's fields, or null when the value has none.

Parameters

value System.Object requiredposition: 0
The value (prepared).
options ConsoleMonster.Values.ShapeOptions requiredposition: 1
Options.

Returns

The adapter, or null.

public static IReadOnlyList<KeyValuePair<String, Object?>> Flatten(Object record, Int32 depth, ShapeOptions? options = null, ShapeBudget? budget = null) #
Returns: IReadOnlyList<KeyValuePair<String, Object?>>

The fields of a record with nested records spread into dotted names (Owner.Name, Owner.Id) down to depth levels. Collections stay one value; a record seen again on the way down becomes (cycle).

Parameters

record System.Object requiredposition: 0
The record.
depth System.Int32 requiredposition: 1
How many levels of nesting to spread (1 = one level).
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 2
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optionalposition: 3
The pass budget, or null.

Returns

The dotted names and values.

public static Boolean IsPlumbing(String name) #
Returns: Boolean

Whether a member name is plumbing (provider paths, CIM metadata, collection synchronisation, DOM links).

Parameters

name System.String requiredposition: 0
The member name.

Returns

True for plumbing.

public static Boolean IsScalar(Object? value) #
Returns: Boolean

Whether a value is shown as one value: ObjectInspector.IsScalarValue plus secure strings.

Parameters

value System.Object? requiredposition: 0
The value (already prepared).

Returns

True for a scalar.

public static Boolean IsStructural(Object? value) #
Returns: Boolean

Whether a value is read by a built-in data adapter (a dictionary, data row, XML element, JSON object or node, file or folder, dictionary entry) or is a data table or view: its keys or columns are its fields, whatever wraps it.

Parameters

value System.Object? requiredposition: 0
The value (unwrapped).

Returns

True for a structural value.

public static Object? Prepare(Object? value, ShapeOptions? options = null) #
Returns: Object?

The value to show for value: wrappers unwrapped, registered shapers applied, an XML document as its root element, a text-only XML element as its text, JSON scalars as .NET scalars and DBNull as null.

Parameters

value System.Object? requiredposition: 0
The value.
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.

Returns

The prepared value.

public static Object? Read(InspectMember member, ShapeBudget? budget = null) #
Returns: Object?

Reads one field: the value, a FieldError when the getter throws, or BudgetExceeded once the budget is spent.

Parameters

member ConsoleMonster.Data.InspectMember requiredposition: 0
The field.
budget ConsoleMonster.Values.ShapeBudget? = null optionalposition: 1
The pass budget, or null for none.

Returns

The value or a marker.

Register 2 overloads
public static Void Register(Type type, Func<Object, Object?> shaper) #
Returns: Void

Registers a shaper for a type (and types derived from it): values of that type are replaced by what it returns before they are shown.

Parameters

type System.Type requiredposition: 0
The type.
shaper System.Func<System.Object, System.Object?> requiredposition: 1
Returns the value to show instead (for example an ordered dictionary), or the value itself.
public static Void Register(String typeName, Func<Object, Object?> shaper) #
Returns: Void

Registers a shaper for a type name: the full name of the value's type or a base type, or any name ShapeOptions.TypeNames reports (PowerShell type names, so deserialized objects can opt in).

Parameters

typeName System.String requiredposition: 0
The type name.
shaper System.Func<System.Object, System.Object?> requiredposition: 1
Returns the value to show instead.
public static Void RegisterAdapter(IMemberSource adapter) #
Returns: Void

Registers a record adapter, tried before the built-in ones.

Parameters

adapter ConsoleMonster.Data.IMemberSource requiredposition: 0
The adapter.
public static Void Register<T>(Func<T, Object?> shaper) #
Returns: Void

Registers a shaper for T.

Type Parameters

T
The type.

Parameters

shaper System.Func<T, System.Object?> requiredposition: 0
Returns the value to show instead.
public static String ScalarText(Object? value, ShapeOptions? options = null) #
Returns: String

A scalar as text: secure strings masked, byte arrays as their size, dates as yyyy-MM-dd HH:mm in local time (as tables show them), numbers and the rest in the culture.

Parameters

value System.Object? requiredposition: 0
The scalar.
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.

Returns

The text.

public static ValueShape ShapeOf(Object? value, ShapeOptions? options = null) #
Returns: ValueShape

What value is for display: empty, scalar, record or collection.

Parameters

value System.Object? requiredposition: 0
The value.
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.

Returns

The shape.

public static String Text(Object? value, ShapeOptions? options = null, ShapeBudget? budget = null) #
Returns: String

A value as one line of text, as it appears inside a cell, a title or a joined list: scalars in the culture, collections by ShapeOptions.Collections, a dictionary as Key=Value pairs, another record as its title, a secure string as ValueShaper.SecureText, a byte array as its size.

Parameters

value System.Object? requiredposition: 0
The value.
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optionalposition: 2
The pass budget, or null.

Returns

The text.

public static String Title(Object record, ShapeOptions? options = null, ShapeBudget? budget = null, Boolean withId = true) #
Returns: String

The title of a record: the first name-like field (see ValueShaper.TitleIndex) with a short text value, then the first short text field, never a Boolean, date, number (except an Id or Key), collection or nested record; the type name when nothing qualifies. With withId, an Id next to a name is added: pwsh (90836).

Parameters

record System.Object requiredposition: 0
The record (prepared).
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optionalposition: 2
The pass budget, or null.
withId System.Boolean = true optionalposition: 3
Whether to add the Id after a name.

Returns

The title.

public static Int32 TitleIndex(IReadOnlyList<String> names) #
Returns: Int32

The index of the field that titles a record, by name: Name, DisplayName, the first other …Name (ProcessName, ServiceName, SamAccountName), then Title, Label, Caption, Key, Id, Identity.

Parameters

names System.Collections.Generic.IReadOnlyList<System.String> requiredposition: 0
The field names.

Returns

The index, or -1 when no name qualifies.

public static Boolean TryGetField(Object record, String name, out Object? value, ShapeOptions? options = null, ShapeBudget? budget = null) #
Returns: Boolean

Reads a named field of a record, preferring exact spelling before a case-insensitive match, or returns false when absent.

Parameters

record System.Object requiredposition: 0
The record (prepared).
name System.String requiredposition: 1
The field name.
value System.Object? requiredposition: 2
The value or a marker (see ValueShaper.Read).
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 3
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optionalposition: 4
The pass budget, or null.

Returns

True when the field exists.

public static Boolean TryGetItems(Object? value, out IEnumerable? items) #
Returns: Boolean

The items of a collection: arrays, lists and other sequences (never a string, a dictionary, a byte array or an XML node), a data table's rows, a data set's tables and a JSON array's values.

Parameters

value System.Object? requiredposition: 0
The value (prepared).
items System.Collections.IEnumerable? requiredposition: 1
The items.

Returns

True for a collection.

public static String TypeName(Object value, ShapeOptions? options = null) #
Returns: String

A short type name for a value: the adapter's name, an XML element's tag, or the .NET type name.

Parameters

value System.Object requiredposition: 0
The value (prepared).
options ConsoleMonster.Values.ShapeOptions? = null optionalposition: 1
Options, or null.

Returns

The name.

Unregister 2 overloads
public static Boolean Unregister(String typeName) #
Returns: Boolean

Removes the shaper registered for a type name.

Parameters

typeName System.String requiredposition: 0
The type name.

Returns

True when one was removed.

public static Boolean Unregister(Type type) #
Returns: Boolean

Removes the shaper registered for a type.

Parameters

type System.Type requiredposition: 0
The type.

Returns

True when one was removed.

public static Boolean UnregisterAdapter(IMemberSource adapter) #
Returns: Boolean

Removes a registered record adapter.

Parameters

adapter ConsoleMonster.Data.IMemberSource requiredposition: 0
The adapter.

Returns

True when it was removed.

Fields

public const String SecureText #

The text a secure string is shown as: never its content or length.

Value: ••••••