Class ObjectExtensions
- Namespace
- CarinaStudio
- Assembly
- CarinaStudio.AppBase.Core.dll
Extensions for all types.
public static class ObjectExtensions
- Inheritance
-
ObjectExtensions
- Inherited Members
Methods
AddWeakEventHandler<TObject>(TObject, string, Action)
Add weak event handler.
public static IDisposable AddWeakEventHandler<TObject>(this TObject target, string eventName, Action handler)
Parameters
Returns
- IDisposable
IDisposable which represents added weak event handler. You can call Dispose() to remove weak event handler explicitly.
Type Parameters
TObject
AddWeakEventHandler<TObject>(TObject, string, EventHandler)
Add weak event handler.
public static IDisposable AddWeakEventHandler<TObject>(this TObject target, string eventName, EventHandler handler)
Parameters
target
TObjecteventName
stringName of event.
handler
EventHandlerEvent handler.
Returns
- IDisposable
IDisposable which represents added weak event handler. You can call Dispose() to remove weak event handler explicitly.
Type Parameters
TObject
AddWeakEventHandler<TObject, TArg>(TObject, string, Action<TArg>)
Add weak event handler.
public static IDisposable AddWeakEventHandler<TObject, TArg>(this TObject target, string eventName, Action<TArg> handler)
Parameters
Returns
- IDisposable
IDisposable which represents added weak event handler. You can call Dispose() to remove weak event handler explicitly.
Type Parameters
TObject
TArg
AddWeakEventHandler<TObject, TArgs>(TObject, string, EventHandler<TArgs>)
Add weak event handler.
public static IDisposable AddWeakEventHandler<TObject, TArgs>(this TObject target, string eventName, EventHandler<TArgs> handler) where TArgs : EventArgs
Parameters
target
TObjecteventName
stringName of event.
handler
EventHandler<TArgs>Event handler.
Returns
- IDisposable
IDisposable which represents added weak event handler. You can call Dispose() to remove weak event handler explicitly.
Type Parameters
TObject
TArgs
AddWeakEventHandler<TObject, TArg1, TArg2>(TObject, string, Action<TArg1, TArg2>)
Add weak event handler.
public static IDisposable AddWeakEventHandler<TObject, TArg1, TArg2>(this TObject target, string eventName, Action<TArg1, TArg2> handler)
Parameters
Returns
- IDisposable
IDisposable which represents added weak event handler. You can call Dispose() to remove weak event handler explicitly.
Type Parameters
TObject
TArg1
TArg2
AddWeakEventHandler<TObject, TArg1, TArg2, TArg3>(TObject, string, Action<TArg1, TArg2, TArg3>)
Add weak event handler.
public static IDisposable AddWeakEventHandler<TObject, TArg1, TArg2, TArg3>(this TObject target, string eventName, Action<TArg1, TArg2, TArg3> handler)
Parameters
Returns
- IDisposable
IDisposable which represents added weak event handler. You can call Dispose() to remove weak event handler explicitly.
Type Parameters
TObject
TArg1
TArg2
TArg3
AlsoAsync<T>(T?, RefInFunc<T?, Task>)
Perform asynchronous action on the given value, and return it.
public static Task<T?> AlsoAsync<T>(this T? value, RefInFunc<T?, Task> action) where T : struct
Parameters
Returns
- Task<T?>
Task of asynchronous action. The result value which is same as
value
.
Type Parameters
T
Type of value.
AlsoAsync<T>(T, RefInFunc<T, Task>)
Perform asynchronous action on the given value, and return it.
public static Task<T> AlsoAsync<T>(this T value, RefInFunc<T, Task> action) where T : struct
Parameters
Returns
- Task<T>
Task of asynchronous action. The result value which is same as
value
.
Type Parameters
T
Type of value.
AlsoAsync<T>(T, Func<T, Task>)
Perform asynchronous action on the given value, and return it.
public static Task<T> AlsoAsync<T>(this T value, Func<T, Task> action) where T : class?
Parameters
Returns
- Task<T>
Task of asynchronous action. The result value which is same as
value
.
Type Parameters
T
Type of value.
Also<T>(T?, RefAction<T?>)
Perform action on the given value, and return it.
public static T? Also<T>(this T? value, RefAction<T?> action) where T : struct
Parameters
value
T?Given value.
action
RefAction<T?>Action to perform on
value
.
Returns
- T?
Value which is same as
value
.
Type Parameters
T
Type of value.
Also<T>(T, RefAction<T>)
Perform action on the given value, and return it.
public static T Also<T>(this T value, RefAction<T> action) where T : struct
Parameters
value
TGiven value.
action
RefAction<T>Action to perform on
value
.
Returns
- T
Value which is same as
value
.
Type Parameters
T
Type of value.
Also<T>(T, Action<T>)
Perform action on the given value, and return it.
public static T Also<T>(this T value, Action<T> action) where T : class?
Parameters
value
TGiven value.
action
Action<T>Action to perform on
value
.
Returns
- T
Value which is same as
value
.
Type Parameters
T
Type of value.
AsNonNull<T>(T?)
Treat given nullable value as non-null value, or throw NullReferenceException.
public static T AsNonNull<T>(this T? obj) where T : class
Parameters
obj
TGiven nullable value.
Returns
- T
Non-null value.
Type Parameters
T
Type of value.
LetAsync<T>(T, Func<T, Task>)
Perform asynchronous action on the given value.
public static Task LetAsync<T>(this T value, Func<T, Task> action)
Parameters
Returns
- Task
Task of asynchronous action.
Type Parameters
T
Type of given value.
LetAsync<T, R>(T, Func<T, Task<R>>)
Perform asynchronous action on the given value, and return a custom value.
public static Task<R> LetAsync<T, R>(this T value, Func<T, Task<R>> action)
Parameters
Returns
- Task<R>
Task of asynchronous action.
Type Parameters
T
Type of given value.
R
Type of return value.
Let<T>(T, Action<T>)
Perform action on the given value.
public static void Let<T>(this T value, Action<T> action)
Parameters
value
TGiven value.
action
Action<T>Action to perform on
value
.
Type Parameters
T
Type of given value.
Let<T, R>(T, RefOutFunc<T, R>)
Perform action on the given value, and return a reference to custom variable.
public static ref R Let<T, R>(this T value, RefOutFunc<T, R> action)
Parameters
value
TGiven value.
action
RefOutFunc<T, R>Action to perform on
value
.
Returns
- R
Reference to custom variable.
Type Parameters
T
Type of given value.
R
Type of return value.
Let<T, R>(T, Func<T, R>)
Perform action on the given value, and return a custom value.
public static R Let<T, R>(this T value, Func<T, R> action)
Parameters
value
TGiven value.
action
Func<T, R>Action to perform on
value
.
Returns
- R
Custom return value.
Type Parameters
T
Type of given value.
R
Type of return value.
LockAsync<T>(T, Func<Task>)
Acquire lock on given object and perform asynchronous action before releasing lock.
public static Task LockAsync<T>(this T obj, Func<Task> action) where T : class
Parameters
Returns
- Task
Task of asynchronous action to generated value.
Type Parameters
T
Type of given object.
LockAsync<T>(T, Func<T, Task>)
Acquire lock on given object and perform asynchronous action before releasing lock.
public static Task LockAsync<T>(this T obj, Func<T, Task> action) where T : class
Parameters
Returns
- Task
Task of asynchronous action to generated value.
Type Parameters
T
Type of given object.
LockAsync<T, R>(T, Func<Task<R>>)
Acquire lock on given object and generate value asynchronously before releasing lock.
public static Task<R> LockAsync<T, R>(this T obj, Func<Task<R>> func) where T : class
Parameters
Returns
- Task<R>
Task of generating value asynchronously.
Type Parameters
T
Type of given object.
R
Type of generated value.
LockAsync<T, R>(T, Func<T, Task<R>>)
Acquire lock on given object and generate value asynchronously before releasing lock.
public static Task<R> LockAsync<T, R>(this T obj, Func<T, Task<R>> func) where T : class
Parameters
Returns
- Task<R>
Task of generating value asynchronously.
Type Parameters
T
Type of given object.
R
Type of generated value.
Lock<T>(T, Action)
Acquire lock on given object and perform action before releasing lock.
public static void Lock<T>(this T obj, Action action) where T : class
Parameters
obj
TObject to acquire lock on.
action
ActionAction to perform.
Type Parameters
T
Type of given object.
Lock<T>(T, Action<T>)
Acquire lock on given object and perform action before releasing lock.
public static void Lock<T>(this T obj, Action<T> action) where T : class
Parameters
obj
TObject to acquire lock on.
action
Action<T>Action to perform.
Type Parameters
T
Type of given object.
Lock<T, R>(T, RefOutFunc<T, R>)
Acquire lock on given object and generate reference to value before releasing lock.
public static ref R Lock<T, R>(this T obj, RefOutFunc<T, R> func) where T : class
Parameters
obj
TObject to acquire lock on.
func
RefOutFunc<T, R>Function to generate reference to value.
Returns
- R
Generated reference to value.
Type Parameters
T
Type of given object.
R
Type of generated value.
Lock<T, R>(T, RefOutFunc<R>)
Acquire lock on given object and generate reference to value before releasing lock.
public static ref R Lock<T, R>(this T obj, RefOutFunc<R> func) where T : class
Parameters
obj
TObject to acquire lock on.
func
RefOutFunc<R>Function to generate reference to value.
Returns
- R
Generated reference to value.
Type Parameters
T
Type of given object.
R
Type of generated value.
Lock<T, R>(T, Func<T, R>)
Acquire lock on given object and generate value before releasing lock.
public static R Lock<T, R>(this T obj, Func<T, R> func) where T : class
Parameters
obj
TObject to acquire lock on.
func
Func<T, R>Function to generate value.
Returns
- R
Generated value.
Type Parameters
T
Type of given object.
R
Type of generated value.
Lock<T, R>(T, Func<R>)
Acquire lock on given object and generate value before releasing lock.
public static R Lock<T, R>(this T obj, Func<R> func) where T : class
Parameters
obj
TObject to acquire lock on.
func
Func<R>Function to generate value.
Returns
- R
Generated value.
Type Parameters
T
Type of given object.
R
Type of generated value.
TryCastAndRunAsync<T>(object?, Func<T, Task>)
Try casting given object to target type then perform an asynchronous action.
public static Task<bool> TryCastAndRunAsync<T>(this object? obj, Func<T, Task> action)
Parameters
Returns
Type Parameters
T
Target type.
TryCastAndRunAsync<T, R>(object?, Func<T, Task<R>>)
Try casting given object to target type then generate a value asynchronously.
public static Task<R> TryCastAndRunAsync<T, R>(this object? obj, Func<T, Task<R>> func)
Parameters
obj
objectObject.
func
Func<T, Task<R>>Function to generate value if object can be casted to target type.
Returns
- Task<R>
Task of generating value.
Type Parameters
T
Target type.
R
Type of generated value.
TryCastAndRun<T>(object?, Action<T>)
Try casting given object to target type then perform the action.
public static bool TryCastAndRun<T>(this object? obj, Action<T> action)
Parameters
Returns
- bool
True if object can be casted to target type.
Type Parameters
T
Target type.
TryCastAndRun<T, R>(object?, Func<T, R>)
Try casting given object to target type then generate a value.
public static R? TryCastAndRun<T, R>(this object? obj, Func<T, R> func)
Parameters
obj
objectObject.
func
Func<T, R>Function to generate value if object can be casted to target type.
Returns
- R
Generated value.
Type Parameters
T
Target type.
R
Type of generated value.