Table of Contents

Method From

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

From(ReadOnlySpan<KeyValuePair<string, string?>>)

Returns Default when mappings is empty; otherwise creates a new map from them, exactly as the constructor does.

public static RowMap<T> From(ReadOnlySpan<KeyValuePair<string, string?>> mappings)

Parameters

mappings ReadOnlySpan<KeyValuePair<string, string>>

The (property name, column name) pairs; a null column means "do not map this property".

Returns

RowMap<T>

The default map, or a new map built from mappings.

Exceptions

ArgumentException

A pair is invalid: an unknown or unsettable property or constructor parameter, a member named twice, an empty column name, a null column for a required property, or two members reading one column (see RowMap<T>).

InvalidOperationException

The model type cannot be mapped (see RowMap<T>).

From(Delegate, params ReadOnlySpan<KeyValuePair<string, string?>>)

Creates a map that builds each T by calling factory, each of its parameters fed by the column of its name (a pair renames one) under the rules of a constructor parameter.

public static RowMap<T> From(Delegate factory, params ReadOnlySpan<KeyValuePair<string, string?>> pairs)

Parameters

factory Delegate

A delegate returning a T; each parameter is matched to a column by name and is the slot a pair names. No member of T is set afterwards.

pairs ReadOnlySpan<KeyValuePair<string, string>>

The (parameter name, column name) pairs; a null column means "do not map this parameter".

Returns

RowMap<T>

The new map.

Remarks

The pairs a factory map enumerates are the ones it was declared with, not its function: spreading them into a new map ([.. map]) gives a map of the model's own members, and new RowMap<T>(map) throws ArgumentException. Pass the map itself.

Declare it once.

Exceptions

ArgumentNullException

factory is null.

ArgumentException

The factory does not return a T, a parameter is passed by reference or two share a name, or a pair is invalid (see RowMap<T>).

InvalidOperationException

T is a single value such as int or string.