Table of Contents

Class ModelFactoryExtensions

Namespace
ToSic.Eav.Data
Assembly
ToSic.Eav.Data.dll

WIP v21

[WorkInProgressApi("WIP v21")]
public static class ModelFactoryExtensions
Inheritance
object
ModelFactoryExtensions

Methods

As<TModel>(IModelFactory, IEntity?)

WIP, v21 requiring factory...

public static TModel? As<TModel>(this IModelFactory factory, IEntity? entity) where TModel : class, IModelSetup<IEntity>

Parameters

factory IModelFactory
entity IEntity

Returns

TModel

Type Parameters

TModel

Exceptions

ArgumentNullException

First<TModel>(IModelFactory, IEnumerable<IEntity>?, NoParamOrder, string?)

Returns the first entity that matches the specified type name, or null if not found.

public static TModel? First<TModel>(this IModelFactory factory, IEnumerable<IEntity>? list, NoParamOrder npo = default, string? typeName = null) where TModel : class, IModelSetup<IEntity>

Parameters

factory IModelFactory

A factory to create the target model.

list IEnumerable<IEntity>

The collection of entities to search.

npo NoParamOrder

see Convention: Named Parameters

typeName string

The 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

TModel

The target model to convert to.

GetAll<TModel>(IModelFactory, IEnumerable<IEntity>?, NoParamOrder, string?)

Returns a collection of wrapper objects of type TModel for all entities of the specified type name.

public static IEnumerable<TModel?> GetAll<TModel>(this IModelFactory factory, IEnumerable<IEntity>? list, NoParamOrder npo = default, string? typeName = null) where TModel : class, IModelSetup<IEntity>

Parameters

factory IModelFactory

The factory to use for creating wrapper instances.

list IEnumerable<IEntity>

The source collection of entities to search. Can be null.

npo NoParamOrder

see Convention: Named Parameters

typeName string

The 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

TModel

The model type to wrap each entity. Must implement IWrapperSetup{IEntity} and have a parameterless constructor.