Skip to content
ConsoleMonster
Class

ValueShaper

ConsoleMonster.Values

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) #

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 object? required
The value.
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optional
The pass budget, or null.

Returns

object? A scalar, a string or a TableCell.
public static IReadOnlyList<InspectMember> Fields(object record, ShapeOptions? options = null) #

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 object required
The record (prepared).
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.

Returns

IReadOnlyList<InspectMember> 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) #

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

Parameters

value object required
The value (prepared).
options ConsoleMonster.Values.ShapeOptions required
Options.

Returns

IMemberSource? The adapter, or null.
public static IReadOnlyList<KeyValuePair<string, object?>> Flatten(object record, int depth, ShapeOptions? options = null, ShapeBudget? budget = null) #

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 object required
The record.
depth int required
How many levels of nesting to spread (1 = one level).
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optional
The pass budget, or null.

Returns

IReadOnlyList<KeyValuePair<string, object?>> The dotted names and values.
public static bool IsPlumbing(string name) #

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

Parameters

name string required
The member name.

Returns

bool True for plumbing.
public static bool IsScalar(object? value) #

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

Parameters

value object? required
The value (already prepared).

Returns

bool True for a scalar.
public static bool IsStructural(object? value) #

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 object? required
The value (unwrapped).

Returns

bool True for a structural value.
public static object? Prepare(object? value, ShapeOptions? options = null) #

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 object? required
The value.
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.

Returns

object? The prepared value.
public static object? Read(InspectMember member, ShapeBudget? budget = null) #

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

Parameters

member ConsoleMonster.Data.InspectMember required
The field.
budget ConsoleMonster.Values.ShapeBudget? = null optional
The pass budget, or null for none.

Returns

object? The value or a marker.
Register 2 overloads
public static void Register(Type type, Func<object, object?> shaper) #

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 required
The type.
shaper System.Func<object, object?> required
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) #

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 string required
The type name.
shaper System.Func<object, object?> required
Returns the value to show instead.
public static void RegisterAdapter(IMemberSource adapter) #

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

Parameters

adapter ConsoleMonster.Data.IMemberSource required
The adapter.
public static void Register<T>(Func<T, object?> shaper) #

Registers a shaper for T.

Type Parameters

T
The type.

Parameters

shaper System.Func<T, object?> required
Returns the value to show instead.
public static string ScalarText(object? value, ShapeOptions? options = null) #

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 object? required
The scalar.
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.

Returns

string The text.
public static ValueShape ShapeOf(object? value, ShapeOptions? options = null) #

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

Parameters

value object? required
The value.
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.

Returns

ValueShape The shape.
public static string Text(object? value, ShapeOptions? options = null, ShapeBudget? budget = null) #

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 object? required
The value.
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optional
The pass budget, or null.

Returns

string The text.
public static string Title(object record, ShapeOptions? options = null, ShapeBudget? budget = null, bool withId = true) #

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 object required
The record (prepared).
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optional
The pass budget, or null.
withId bool = true optional
Whether to add the Id after a name.

Returns

string The title.
public static int TitleIndex(IReadOnlyList<string> names) #

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<string> required
The field names.

Returns

int The index, or -1 when no name qualifies.
public static bool TryGetField(object record, string name, out object? value, ShapeOptions? options = null, ShapeBudget? budget = null) #

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

Parameters

record object required
The record (prepared).
name string required
The field name.
value object? required
The value or a marker (see ValueShaper.Read).
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.
budget ConsoleMonster.Values.ShapeBudget? = null optional
The pass budget, or null.

Returns

bool True when the field exists.
public static bool TryGetItems(object? value, out IEnumerable? items) #

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 object? required
The value (prepared).
items System.Collections.IEnumerable? required
The items.

Returns

bool True for a collection.
public static string TypeName(object value, ShapeOptions? options = null) #

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

Parameters

value object required
The value (prepared).
options ConsoleMonster.Values.ShapeOptions? = null optional
Options, or null.

Returns

string The name.
Unregister 2 overloads
public static bool Unregister(string typeName) #

Removes the shaper registered for a type name.

Parameters

typeName string required
The type name.

Returns

bool True when one was removed.
public static bool Unregister(Type type) #

Removes the shaper registered for a type.

Parameters

type System.Type required
The type.

Returns

bool True when one was removed.
public static bool UnregisterAdapter(IMemberSource adapter) #

Removes a registered record adapter.

Parameters

adapter ConsoleMonster.Data.IMemberSource required
The adapter.

Returns

bool True when it was removed.

Fields

public const string SecureText #

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

Value: ••••••