ValueShaper
ConsoleMonster.Values
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?
- The value.
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
- budget ConsoleMonster.Values.ShapeBudget? = null
- The pass budget, or null.
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
- The record (prepared).
- options ConsoleMonster.Values.ShapeOptions? = null
- 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
- The value (prepared).
- options ConsoleMonster.Values.ShapeOptions
- Options.
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
- The record.
- depth int
- How many levels of nesting to spread (1 = one level).
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
- budget ConsoleMonster.Values.ShapeBudget? = null
- 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
- 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?
- 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?
- 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?
- The value.
- options ConsoleMonster.Values.ShapeOptions? = null
- 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
- The field.
- budget ConsoleMonster.Values.ShapeBudget? = null
- The pass budget, or null for none.
Returns
object? The value or a marker.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
- The type.
- shaper System.Func<object, object?>
- 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
- The type name.
- shaper System.Func<object, object?>
- 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
- 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?>
- 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?
- The scalar.
- options ConsoleMonster.Values.ShapeOptions? = null
- 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?
- The value.
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
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?
- The value.
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
- budget ConsoleMonster.Values.ShapeBudget? = null
- 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
- The record (prepared).
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
- budget ConsoleMonster.Values.ShapeBudget? = null
- The pass budget, or null.
- withId bool = true
- 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>
- 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
- The record (prepared).
- name string
- The field name.
- value object?
- The value or a marker (see ValueShaper.Read).
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
- budget ConsoleMonster.Values.ShapeBudget? = null
- 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?
- The value (prepared).
- items System.Collections.IEnumerable?
- 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
- The value (prepared).
- options ConsoleMonster.Values.ShapeOptions? = null
- Options, or null.
Returns
string The name.public static bool Unregister(string typeName) #Removes the shaper registered for a type name.
Parameters
- typeName string
- 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
- 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
- The adapter.
Returns
bool True when it was removed.Inherited Methods
Fields
public const string SecureText #The text a secure string is shown as: never its content or length.
••••••