Class AbpObjectExtensions
- Namespace
- System
- Assembly
- Volo.Abp.Core.dll
Extension methods for all objects.
public static class AbpObjectExtensions
- Inheritance
-
AbpObjectExtensions
- Inherited Members
Methods
As<T>(object)
Used to simplify and beautify casting an object to a type.
public static T As<T>(this object obj) where T : class
Parameters
obj
objectObject to cast
Returns
- T
Casted object
Type Parameters
T
Type to be casted
If<T>(T, bool, Action<T>)
Can be used to conditionally perform an action on an object and return the original object. It is useful for chained calls on the object.
public static T If<T>(this T obj, bool condition, Action<T> action)
Parameters
obj
TAn object
condition
boolA condition
action
Action<T>An action that is executed only if the condition is
true
Returns
- T
Returns the original object.
Type Parameters
T
Type of the object
If<T>(T, bool, Func<T, T>)
Can be used to conditionally perform a function on an object and return the modified or the original object. It is useful for chained calls.
public static T If<T>(this T obj, bool condition, Func<T, T> func)
Parameters
obj
TAn object
condition
boolA condition
func
Func<T, T>A function that is executed only if the condition is
true
Returns
- T
Returns the modified object (by the
func
if thecondition
is
) or the original object if thetrue
condition
isfalse
Type Parameters
T
Type of the object
IsIn<T>(T, IEnumerable<T>)
Check if an item is in the given enumerable.
public static bool IsIn<T>(this T item, IEnumerable<T> items)
Parameters
item
TItem to check
items
IEnumerable<T>Items
Returns
Type Parameters
T
Type of the items
IsIn<T>(T, params T[])
Check if an item is in a list.
public static bool IsIn<T>(this T item, params T[] list)
Parameters
item
TItem to check
list
T[]List of items
Returns
Type Parameters
T
Type of the items
To<T>(object)
Converts given object to a value type using ChangeType(object, Type) method.
public static T To<T>(this object obj) where T : struct
Parameters
obj
objectObject to be converted
Returns
- T
Converted object
Type Parameters
T
Type of the target object