Class EntityListExtensions
Helper extensions for lists of entities.
[PublicApi]
public static class EntityListExtensions
- Inheritance
-
objectEntityListExtensions
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
listIEnumerable<IEntity>idint
Returns
First(IEnumerable<IEntity>, string)
Returns the first entity that matches the specified type name, or null if not found.
public static IEntity? First(this IEnumerable<IEntity> list, string typeName)
Parameters
listIEnumerable<IEntity>The collection of entities to search.
typeNamestringThe name of the type to match. This comparison is case-sensitive.
Returns
- IEntity
The first entity whose type matches the specified type name, or null if no matching entity is found.
First<TModel>(IEnumerable<IEntity>?)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? First<TModel>(this IEnumerable<IEntity>? list) where TModel : class, IModelSetup<IEntity>, 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.
First<TModel>(IEnumerable<IEntity>?, NoParamOrder, string?, ModelNullHandling)
Returns the first entity that matches the specified type name, or null if not found.
public static TModel? First<TModel>(this IEnumerable<IEntity>? list, NoParamOrder npo = default, string? typeName = null, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelSetup<IEntity>, new()
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.
GetAll(IEnumerable<IEntity>, string)
Extract all entities of a specific content type from a list.
public static IEnumerable<IEntity> GetAll(this IEnumerable<IEntity> list, string typeName)
Parameters
listIEnumerable<IEntity>typeNamestring
Returns
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 : class, IModelSetup<IEntity>, new()
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
IWrapperSetup{IEntity}and have a parameterless constructor.
GetAll<TModel>(IEnumerable<IEntity>?, NoParamOrder, string?, ModelNullHandling)
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, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelSetup<IEntity>, new()
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
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
listIEnumerable<IEntity>guidGuid
Returns
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
listIEnumerable<IEntity>idint
Returns
GetOne<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? GetOne<TModel>(this IEnumerable<IEntity>? list, Guid guid, NoParamOrder npo = default, bool skipTypeCheck = false, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelSetup<IEntity>, 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.
GetOne<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? GetOne<TModel>(this IEnumerable<IEntity>? list, int id, NoParamOrder npo = default, bool skipTypeCheck = false, ModelNullHandling nullHandling = ModelNullHandling.Undefined) where TModel : class, IModelSetup<IEntity>, 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.