Class ToModelExtensions
Extension methods to convert IEntity or lists of IEntity to Models. WIP v21 TODO DOCS
[WorkInProgressApi("WIP v21")]
public static class ToModelExtensions
- Inheritance
-
objectToModelExtensions
Methods
FirstModel<TModel>(IEnumerable<IEntity>?)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? FirstModel<TModel>(this IEnumerable<IEntity>? list) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
Returns
- TModel
The first entity whose type matches the specified type name wrapped into the target model, or null if no matching entity is found.
Type Parameters
TModelThe target model to convert to.
FirstModel<TModel>(IEnumerable<IEntity>?, IModelFactory, NoParamOrder, ToModelOptions?)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? FirstModel<TModel>(this IEnumerable<IEntity>? list, IModelFactory factory, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
factoryIModelFactoryA factory to create the target model.
npoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
The first entity whose type matches the specified type name wrapped into the target model, or null if no matching entity is found.
Type Parameters
TModelThe target model to convert to.
FirstModel<TModel>(IEnumerable<IEntity>?, NoParamOrder, ToModelOptions?)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? FirstModel<TModel>(this IEnumerable<IEntity>? list, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
npoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
The first entity whose type matches the specified type name wrapped into the target model, or null if no matching entity is found.
Type Parameters
TModelThe target model to convert to.
GetMetadataModel<TModel>(IHasMetadata)
Get a typed metadata from an object which has metadata.
Will return null if no data found.
public static TModel? GetMetadataModel<TModel>(this IHasMetadata parent) where TModel : class, IModelFromEntity
Parameters
parentIHasMetadataAn object which has metadata.
Returns
- TModel
Type Parameters
TModelAny model object or interface.
GetMetadataModel<TModel>(IHasMetadata, IModelFactory, NoParamOrder, ToModelOptions?)
public static TModel? GetMetadataModel<TModel>(this IHasMetadata parent, IModelFactory factory, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
parentIHasMetadatafactoryIModelFactorynpoNoParamOrderoptionsToModelOptions
Returns
- TModel
Type Parameters
TModel
GetMetadataModel<TModel>(IHasMetadata, NoParamOrder, ToModelOptions?)
Get a typed metadata from an object which has metadata.
Will return null if no data found, unless specified otherwise in the options.
public static TModel? GetMetadataModel<TModel>(this IHasMetadata parent, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
parentIHasMetadataAn object which has metadata.
npoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
Type Parameters
TModelAny model object or interface.
GetModel<TModel>(IEnumerable<IEntity>?, Guid, NoParamOrder, ToModelOptions?)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? GetModel<TModel>(this IEnumerable<IEntity>? list, Guid guid, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
guidGuidnpoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
The first entity whose type matches the specified type name wrapped into the target model, or null if no matching entity is found.
Type Parameters
TModelThe target model to convert to.
GetModel<TModel>(IEnumerable<IEntity>?, int, NoParamOrder, ToModelOptions?)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? GetModel<TModel>(this IEnumerable<IEntity>? list, int id, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
idintnpoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
The first entity whose type matches the specified type name wrapped into the target model, or null if no matching entity is found.
Type Parameters
TModelThe target model to convert to.
GetModels<TModel>(IEnumerable<IEntity>?)
Filter data by type matching the model, and return as a collection of type TModel.
public static IEnumerable<TModel?> GetModels<TModel>(this IEnumerable<IEntity>? list) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to filter and wrap.
Returns
- IEnumerable<TModel>
An enumerable collection of wrapped entities of the specified model type. Returns an empty collection if the input is null or contains no matching entities.
Type Parameters
TModelThe model type to wrap each entity. Must implement IModelFromEntity and should implement IModelSetup<TSource>. The type-name being filtered is derived from the model name, or from the ModelSpecsAttribute on the model.
GetModels<TModel>(IEnumerable<IEntity>?, IModelFactory, NoParamOrder, ToModelOptions?)
Returns a collection of wrapper objects of type TModel for all entities of the specified type name.
public static IEnumerable<TModel?> GetModels<TModel>(this IEnumerable<IEntity>? list, IModelFactory factory, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The source collection of entities to search. Can be null.
factoryIModelFactoryThe factory to use for creating wrapper instances.
npoNoParamOrderoptionsToModelOptionsConversion options
Returns
- IEnumerable<TModel>
An enumerable collection of TModel instances wrapping the matching entities. Returns an empty collection if the source is null or no matching entities are found.
Type Parameters
TModelThe model type to wrap each entity. Must implement
IWrapperSetup{IEntity}and have a parameterless constructor.
GetModels<TModel>(IEnumerable<IEntity>?, NoParamOrder, ToModelOptions?)
Filter data by type matching the model, and return as a collection of type TModel.
public static IEnumerable<TModel?> GetModels<TModel>(this IEnumerable<IEntity>? list, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The source collection of entities to search. Can be null.
npoNoParamOrderoptionsToModelOptionsConversion options
Returns
- IEnumerable<TModel>
An enumerable collection of TModel instances wrapping the matching entities. Returns an empty collection if the source is null or no matching entities are found.
Type Parameters
TModelThe model type to wrap each entity. Must implement IModelFromEntity and should implement IModelSetup<TSource>. The type-name being filtered is used from ToModelOptions, derived from the model name, or from the ModelSpecsAttribute on the model.
ToModel<TModel>(ICanBeEntity?, NoParamOrder, ToModelOptions?)
WIP Convert something which can be an entity to a model of type TModel. This is only meant for simple models that do not require a factory.
public static TModel? ToModel<TModel>(this ICanBeEntity? canBeEntity, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
canBeEntityICanBeEntitynpoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
Type Parameters
TModelTModel must implement IWrapperSetup<IEntity> and have a parameterless constructor.
Exceptions
ToModel<TModel>(IEntity?)
WIP Convert an IEntity to a model of type TModel. This is only meant for simple models that do not require a factory.
public static TModel? ToModel<TModel>(this IEntity? entity) where TModel : class, IModelFromEntity
Parameters
entityIEntity
Returns
- TModel
Type Parameters
TModelTModel must implement IWrapperSetup<IEntity> and have a parameterless constructor.
Exceptions
ToModel<TModel>(IEntity, IModelFactory, NoParamOrder, ToModelOptions?)
WIP, v21 requiring factory...
public static TModel? ToModel<TModel>(this IEntity entity, IModelFactory factory, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
entityIEntityfactoryIModelFactorynpoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
Type Parameters
TModel
Exceptions
ToModel<TModel>(IEntity?, NoParamOrder, ToModelOptions?)
WIP Convert an IEntity to a model of type TModel. This is only meant for simple models that do not require a factory.
public static TModel? ToModel<TModel>(this IEntity? entity, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
entityIEntitynpoNoParamOrderoptionsToModelOptionsConversion options
Returns
- TModel
Type Parameters
TModelTModel must implement IWrapperSetup<IEntity> and have a parameterless constructor.
Exceptions
ToModels<TModel>(IEnumerable<IEntity?>?)
public static IEnumerable<TModel> ToModels<TModel>(this IEnumerable<IEntity?>? list) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>
Returns
- IEnumerable<TModel>
Type Parameters
TModel
ToModels<TModel>(IEnumerable<IEntity?>?, IModelFactory, NoParamOrder, ToModelOptions?)
public static IEnumerable<TModel> ToModels<TModel>(this IEnumerable<IEntity?>? list, IModelFactory factory, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>factoryIModelFactorynpoNoParamOrderoptionsToModelOptions
Returns
- IEnumerable<TModel>
Type Parameters
TModel
ToModels<TModel>(IEnumerable<IEntity?>?, NoParamOrder, ToModelOptions?)
public static IEnumerable<TModel> ToModels<TModel>(this IEnumerable<IEntity?>? list, NoParamOrder npo = default, ToModelOptions? options = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>npoNoParamOrderoptionsToModelOptions
Returns
- IEnumerable<TModel>
Type Parameters
TModel