Class ToModelExtensions
Extension methods to convert IEntity or lists of IEntity to Models. WIP v21 TODO DOCS
[WorkInProgressApi("WIP v21")]
[WorkInProgressApi("beta 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, new()
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, string?)
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, string? typeName = null) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
factoryIModelFactoryA factory to create the target model.
npoNoParamOrdertypeNamestringThe name of the type to match.
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, string?, ModelNullHandling)
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, string? typeName = null, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The collection of entities to search.
npoNoParamOrdertypeNamestringThe name of the type to match.
nullHandlingModelNullHandling
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, NoParamOrder)
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, NoParamOrder npo = default) where TModel : class, IModelFromEntity
Parameters
parentIHasMetadataAn object which has metadata.
npoNoParamOrder
Returns
- TModel
Type Parameters
TModelAny model object or interface.
GetModel<TModel>(IEnumerable<IEntity>?, Guid, NoParamOrder, bool, ModelNullHandling)
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, bool skipTypeCheck = false, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelFromEntity, new()
Parameters
listIEnumerable<IEntity>The collection of entities to search.
guidGuidnpoNoParamOrderskipTypeCheckboolnullHandlingModelNullHandling
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, bool, ModelNullHandling)
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, bool skipTypeCheck = false, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelFromEntity, new()
Parameters
listIEnumerable<IEntity>The collection of entities to search.
idintnpoNoParamOrderskipTypeCheckboolnullHandlingModelNullHandling
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, string?)
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, string? typeName = 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.
npoNoParamOrdertypeNamestringThe name identifier of the entity type to filter by. This value is used to select entities of a specific type.
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, string?, ModelNullHandling)
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, string? typeName = null, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelFromEntity
Parameters
listIEnumerable<IEntity>The source collection of entities to search. Can be null.
npoNoParamOrdertypeNamestringThe name identifier of the entity type to filter by. This value is used to select entities of a specific type.
nullHandlingModelNullHandling
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 typeName, derived from the model name, or from the ModelSpecsAttribute on the model.
ToModel<TModel>(ICanBeEntity?, NoParamOrder, bool, ModelNullHandling)
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, bool skipTypeCheck = false, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelFromEntity
Parameters
canBeEntityICanBeEntitynpoNoParamOrderskipTypeCheckboolallow conversion even if the Content-Type of the entity doesn't match the type specified in the parameter T
nullHandlingModelNullHandlingHow to handle nulls during the conversion - default is ToSic.Eav.Models.ModelNullHandling.Default
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)
WIP, v21 requiring factory...
public static TModel? ToModel<TModel>(this IEntity entity, IModelFactory factory) where TModel : class, IModelFromEntity
Parameters
entityIEntityfactoryIModelFactory
Returns
- TModel
Type Parameters
TModel
Exceptions
ToModel<TModel>(IEntity?, NoParamOrder, bool, ModelNullHandling)
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, bool skipTypeCheck = false, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelFromEntity
Parameters
entityIEntitynpoNoParamOrderskipTypeCheckboolallow conversion even if the Content-Type of the entity doesn't match the type specified in the parameter T
nullHandlingModelNullHandlingHow to handle nulls during the conversion - default is ToSic.Eav.Models.ModelNullHandling.Default
Returns
- TModel
Type Parameters
TModelTModel must implement IWrapperSetup<IEntity> and have a parameterless constructor.
Exceptions
ToModels<TModel>(IEnumerable<IEntity?>, NoParamOrder)
public static IEnumerable<TModel> ToModels<TModel>(this IEnumerable<IEntity?> entities, NoParamOrder npo = default) where TModel : class, IModelFromEntity, new()
Parameters
entitiesIEnumerable<IEntity>npoNoParamOrder
Returns
- IEnumerable<TModel>
Type Parameters
TModel