Class CommonExtensions
Common set of extension methods for use within the SDK.
Inheritance
Namespace: Cireson.Core.Common.Extensions
Assembly: Cireson.Core.Common.dll
Syntax
public static class CommonExtensions : object
Remarks
Admin, 8/24/2017.
Methods
View SourceAddIfNotExists<T>(IDbSet<T>, Expression<Func<T, Boolean>>, T)
Adds the entity to the set if it does not exists, does nothibng if the entity exists. This is a parity to the AddOrUpdate extension, and can be used for seeding data during migrations.
Declaration
public static void AddIfNotExists<T>(this IDbSet<T> set, Expression<Func<T, bool>> expression, T item)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDbSet<T> | set | The entity set. |
Expression<Func<T, System.Boolean>> | expression | Entity selector expression. |
T | item | Entity to add. |
Type Parameters
Name | Description |
---|---|
T | . |
Remarks
Admin, 8/24/2017.
AddMultiCardinalityValue<T>(IDictionary<String, Object>, String, T)
This will add an item to the dictionary if the key exists, then rather than replacing, or erroring it will replace the value with an IEnumerable and append the item to the array.
Declaration
public static void AddMultiCardinalityValue<T>(this IDictionary<string, object> dict, string key, T value)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<System.String, System.Object> | dict | Source dictionary. |
System.String | key | . |
T | value | . |
Type Parameters
Name | Description |
---|---|
T | Generic type parameter. |
Remarks
Admin, 8/24/2017.
CompareBytes(Byte[], Byte[])
Compares all bytes in the array.
Declaration
public static bool CompareBytes(this byte[] b1, byte[] b2)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | b1 | . |
System.Byte[] | b2 | . |
Returns
Type | Description |
---|---|
System.Boolean | True if it succeeds, false if it fails. |
Remarks
Admin, 8/24/2017.
CreatePropertyLambda(Type, String)
Creates a property lambda eg: t => t.propertyName based on the type and propertyName.
Declaration
public static Expression CreatePropertyLambda(this Type type, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
Type | type | . |
System.String | propertyName | . |
Returns
Type | Description |
---|---|
Expression | The new property lambda. |
Remarks
Admin, 8/24/2017.
DistinctBy<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>)
An IQueryable<TSource> extension method that distinct by.
Declaration
public static IQueryable<TSource> DistinctBy<TSource, TKey>(this IQueryable<TSource> query, Expression<Func<TSource, TKey>> keySelector)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<TSource> | query | The query to act on. |
Expression<Func<TSource, TKey>> | keySelector | The key selector. |
Returns
Type | Description |
---|---|
IQueryable<TSource> | An IQueryable<TSource> |
Type Parameters
Name | Description |
---|---|
TSource | Type of the source. |
TKey | Type of the key. |
Remarks
Admin, 8/24/2017.
ForEach<T>(IEnumerable<T>, Action<T>)
Iterates through the enumerable, and executes the give action for each element.
Declaration
public static void ForEach<T>(this IEnumerable<T> list, Action<T> action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | list | Source enumerable. |
Action<T> | action | The action to invoke for each item. |
Type Parameters
Name | Description |
---|---|
T | . |
Remarks
Admin, 8/24/2017.
FromJson(Type, String)
Returns an instance of the type from the json string.
Declaration
public static object FromJson(this Type type, string value)
Parameters
Type | Name | Description |
---|---|---|
Type | type | . |
System.String | value | . |
Returns
Type | Description |
---|---|
System.Object | An object. |
Remarks
Admin, 8/24/2017.
GetBaseTypeThatImplements<TType>(Type)
Gets the type in the inheritance chain that first implements the specified interface/base class.
Declaration
public static Type GetBaseTypeThatImplements<TType>(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | . |
Returns
Type | Description |
---|---|
Type | The base type that implements. |
Type Parameters
Name | Description |
---|---|
TType | . |
Remarks
Admin, 8/24/2017.
GetInheritanceChain(Type, Type)
Retrieves the number of generations between the specified type, and the Ancestor Type.
Declaration
public static IEnumerable<Type> GetInheritanceChain(this Type type, Type untilAncestorType)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Derived type to check. |
Type | untilAncestorType | Ancestral type that defines the starting point. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumerator that allows foreach to be used to process the inheritance chains in this collection. |
Remarks
Admin, 8/24/2017.
GetPlatformUserId(IIdentity)
Gets the PlatformUserId for the identity based on the claims.
Declaration
public static long? GetPlatformUserId(this IIdentity identity)
Parameters
Type | Name | Description |
---|---|---|
IIdentity | identity | . |
Returns
Type | Description |
---|---|
System.Nullable<System.Int64> | Platform User Id for the given claim. |
Remarks
Admin, 8/24/2017.
GetPropertyFromExpression<T>(Expression<Func<T, Object>>)
Retrieves a PropertyInfo object from the given property lambda eg: entity => entity.SomeProperty.
Declaration
public static PropertyInfo GetPropertyFromExpression<T>(this Expression<Func<T, object>> getPropertyLambda)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, System.Object>> | getPropertyLambda | . |
Returns
Type | Description |
---|---|
PropertyInfo | The property from expression. |
Type Parameters
Name | Description |
---|---|
T | . |
Remarks
Admin, 8/24/2017.
ToJson(Object)
Returns a json string representation of the object.
Declaration
public static string ToJson(this object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | . |
Returns
Type | Description |
---|---|
System.String | Obj as a string. |
Remarks
Admin, 8/24/2017.