Table of Contents

Class EntityListExtensions

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

Helper extensions for lists of entities.

[PublicApi]
public static class EntityListExtensions
Inheritance
object
EntityListExtensions

Remarks

Has been used internally since forever, made public in v21.

Methods

Contains(IEnumerable<IEntity>, int)

Check if an entity is available. Mainly used in special cases where published/unpublished are hidden/visible

public static bool Contains(this IEnumerable<IEntity> list, int id)

Parameters

list IEnumerable<IEntity>
id int

Returns

bool

GetAll<TModel>(IEnumerable<IEntity>?)

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

public static IEnumerable<TModel> GetAll<TModel>(this IEnumerable<IEntity>? list) where TModel : IWrapperSetup<IEntity>, new()

Parameters

list IEnumerable<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

TModel

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

GetAll<TModel>(IEnumerable<IEntity>?, 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 IEnumerable<IEntity>? list, string typeName) where TModel : IWrapperSetup<IEntity>, new()

Parameters

list IEnumerable<IEntity>

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

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.

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

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

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

Parameters

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.

factory IWrapperFactory

The factory to use for creating wrapper instances.

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.

GetOne(IEnumerable<IEntity>, Guid)

get an entity based on the guid - or null if not found

public static IEntity? GetOne(this IEnumerable<IEntity> list, Guid guid)

Parameters

list IEnumerable<IEntity>
guid Guid

Returns

IEntity

GetOne(IEnumerable<IEntity>, int)

Get an entity with an entity-id - or null if not found

public static IEntity? GetOne(this IEnumerable<IEntity> list, int id)

Parameters

list IEnumerable<IEntity>
id int

Returns

IEntity

GetOne<TModel>(IEnumerable<IEntity>?)

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

public static TModel? GetOne<TModel>(this IEnumerable<IEntity>? list) where TModel : IWrapperSetup<IEntity>, new()

Parameters

list IEnumerable<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

TModel

The target model to convert to.

GetOne<TModel>(IEnumerable<IEntity>?, string)

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

public static TModel? GetOne<TModel>(this IEnumerable<IEntity>? list, string typeName) where TModel : IWrapperSetup<IEntity>, new()

Parameters

list IEnumerable<IEntity>

The collection of entities to search.

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.

GetOne<TModel>(IEnumerable<IEntity>?, NoParamOrder, string?, IWrapperFactory?)

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

public static TModel? GetOne<TModel>(this IEnumerable<IEntity>? list, NoParamOrder npo = default, string? typeName = null, IWrapperFactory? factory = null) where TModel : IWrapperSetup<IEntity>, new()

Parameters

list IEnumerable<IEntity>

The collection of entities to search.

npo NoParamOrder

see Convention: Named Parameters

typeName string

The name of the type to match.

factory IWrapperFactory

A factory to create the target model.

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.