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
mappingsReadOnlySpan<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
factoryDelegateA delegate returning a
T; each parameter is matched to a column by name and is the slot a pair names. No member ofTis set afterwards.pairsReadOnlySpan<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
factoryis 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