Class DelegateHelpers
Represents various extensions of delegates.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
[BeforeFieldInit(true)]
public static class DelegateHelpers
Methods
| Improve this Doc View SourceBind<T>(Action<T>, T)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Action Bind<T>(this Action<T> action, T obj)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to bind. |
T | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Action | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T | The type of the first parameter to bind. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2>(Action<T1, T2>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Action<T2> Bind<T1, T2>(this Action<T1, T2> action, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2> | action | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Action<T2> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T, TResult>(Func<T, TResult>, T)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Func<TResult> Bind<T, TResult>(this Func<T, TResult> func, T obj)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<T, TResult> | func | The action to bind. |
T | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Func<TResult> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T | The type of the first parameter to bind. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, T3>(Action<T1, T2, T3>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Action<T2, T3> Bind<T1, T2, T3>(this Action<T1, T2, T3> action, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3> | action | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Action<T2, T3> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
T3 | The type of the third parameter. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, TResult>(Func<T1, T2, TResult>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Func<T2, TResult> Bind<T1, T2, TResult>(this Func<T1, T2, TResult> func, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, TResult> | func | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Func<T2, TResult> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, T3, T4>(Action<T1, T2, T3, T4>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Action<T2, T3, T4> Bind<T1, T2, T3, T4>(this Action<T1, T2, T3, T4> action, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4> | action | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Action<T2, T3, T4> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
T3 | The type of the third parameter. |
T4 | The type of the fourth parameter. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Func<T2, T3, TResult> Bind<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> func, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, TResult> | func | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Func<T2, T3, TResult> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
T3 | The type of the third parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Action<T2, T3, T4, T5> Bind<T1, T2, T3, T4, T5>(this Action<T1, T2, T3, T4, T5> action, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5> | action | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Action<T2, T3, T4, T5> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
T3 | The type of the third parameter. |
T4 | The type of the fourth parameter. |
T5 | The type of the fifth parameter. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Func<T2, T3, T4, TResult> Bind<T1, T2, T3, T4, TResult>(this Func<T1, T2, T3, T4, TResult> func, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, TResult> | func | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Func<T2, T3, T4, TResult> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
T3 | The type of the third parameter. |
T4 | The type of the fourth parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Bind<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult>, T1)
Produces delegate which first parameter is implicitly bound to the given object.
Declaration
public static Func<T2, T3, T4, T5, TResult> Bind<T1, T2, T3, T4, T5, TResult>(this Func<T1, T2, T3, T4, T5, TResult> func, T1 obj)
where T1 : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, TResult> | func | The action to bind. |
T1 | obj | The object to be passed implicitly as the first argument into the method represented by this pointer. Cannot be null. |
Returns
Type | Description |
---|---|
Func<T2, T3, T4, T5, TResult> | The delegate targeting the specified object. |
Type Parameters
Name | Description |
---|---|
T1 | The type of the first parameter to bind. |
T2 | The type of the second parameter. |
T3 | The type of the third parameter. |
T4 | The type of the fourth parameter. |
T5 | The type of the fifth parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ChangeType<TDelegate>(Delegate)
Returns a new delegate of different type which points to the same method as original delegate.
Declaration
public static TDelegate ChangeType<TDelegate>(this Delegate d)
where TDelegate : Delegate
Parameters
Type | Name | Description |
---|---|---|
Delegate | d | Delegate to convert. |
Returns
Type | Description |
---|---|
TDelegate | A method wrapped into new delegate type. |
Type Parameters
Name | Description |
---|---|
TDelegate | A new delegate type. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Cannot convert delegate type. |
Contravariant<TBase, T>(EventHandler<TBase>)
Performs contravariant conversion of actual generic argument specified for EventHandler<TEventArgs> type.
Declaration
public static EventHandler<T> Contravariant<TBase, T>(this EventHandler<TBase> handler)
where TBase : class where T : class, TBase
Parameters
Type | Name | Description |
---|---|---|
EventHandler<TBase> | handler | The handler to convert. |
Returns
Type | Description |
---|---|
EventHandler<T> | The delegate referencing the same method as original delegate. |
Type Parameters
Name | Description |
---|---|
TBase | Input type of the delegate. |
T | A subtype of |
Remarks
Generic parameter of delegate EventHandler<TEventArgs> is not marked as langword_csharp_in so compiler doesn't support contravariant conversion for it. This method provides contravariant conversion for this delegate type.
CreateClosedDelegateFactory<TDelegate>(Expression<TDelegate>)
Creates a factory for closed delegates.
Declaration
public static Func<object, TDelegate> CreateClosedDelegateFactory<TDelegate>(Expression<TDelegate> expression)
where TDelegate : Delegate
Parameters
Type | Name | Description |
---|---|---|
Expression<TDelegate> | expression | The expression tree containing instance method, property, operator call. |
Returns
Type | Description |
---|---|
Func<Object, TDelegate> | The factory of closed delegate. |
Type Parameters
Name | Description |
---|---|
TDelegate | The type of the delegate describing expression tree. |
CreateDelegate<TDelegate>(MethodInfo, Object)
Creates a delegate of the specified type with the specified target from this method.
Declaration
public static TDelegate CreateDelegate<TDelegate>(this MethodInfo method, object target = null)
where TDelegate : Delegate
Parameters
Type | Name | Description |
---|---|---|
MethodInfo | method | The method to be wrapped into delegate. |
Object | target | The object targeted by the delegate. |
Returns
Type | Description |
---|---|
TDelegate | The delegate for the specified method. |
Type Parameters
Name | Description |
---|---|
TDelegate | The type of the delegate to create. |
See Also
| Improve this Doc View SourceCreateOpenDelegate<TDelegate>(Expression<TDelegate>)
Creates open delegate for the instance method, property, operator referenced in expression tree.
Declaration
public static TDelegate CreateOpenDelegate<TDelegate>(Expression<TDelegate> expression)
where TDelegate : Delegate
Parameters
Type | Name | Description |
---|---|---|
Expression<TDelegate> | expression | The expression tree containing instance method call. |
Returns
Type | Description |
---|---|
TDelegate | The open delegate. |
Type Parameters
Name | Description |
---|---|
TDelegate | The type of the delegate describing expression tree. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
CreateOpenDelegate<T, TValue>(Expression<Func<T, TValue>>)
Creates open delegate for instance property setter.
Declaration
public static Action<T, TValue> CreateOpenDelegate<T, TValue>(Expression<Func<T, TValue>> properyExpr)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TValue>> | properyExpr | The expression representing property. |
Returns
Type | Description |
---|---|
Action<T, TValue> | The open delegate representing property setter. |
Type Parameters
Name | Description |
---|---|
T | The declaring type. |
TValue | The type of property value. |
Unbind<T>(Action)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Action<T> Unbind<T>(this Action action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action | action | The delegate to unbind. |
Returns
Type | Description |
---|---|
Action<T> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, TArg>(Action<TArg>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Action<T, TArg> Unbind<T, TArg>(this Action<TArg> action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action<TArg> | action | The delegate to unbind. |
Returns
Type | Description |
---|---|
Action<T, TArg> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
TArg | The type of the first explicit parameter. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, TResult>(Func<TResult>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Func<T, TResult> Unbind<T, TResult>(this Func<TResult> func)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<TResult> | func | The delegate to unbind. |
Returns
Type | Description |
---|---|
Func<T, TResult> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2>(Action<T1, T2>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Action<T, T1, T2> Unbind<T, T1, T2>(this Action<T1, T2> action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2> | action | The delegate to unbind. |
Returns
Type | Description |
---|---|
Action<T, T1, T2> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, TArg, TResult>(Func<TArg, TResult>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Func<T, TArg, TResult> Unbind<T, TArg, TResult>(this Func<TArg, TResult> func)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<TArg, TResult> | func | The delegate to unbind. |
Returns
Type | Description |
---|---|
Func<T, TArg, TResult> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
TArg | The type of the first explicit parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, T3>(Action<T1, T2, T3>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Action<T, T1, T2, T3> Unbind<T, T1, T2, T3>(this Action<T1, T2, T3> action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3> | action | The delegate to unbind. |
Returns
Type | Description |
---|---|
Action<T, T1, T2, T3> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
T3 | The type of the third explicit parameter. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, TResult>(Func<T1, T2, TResult>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Func<T, T1, T2, TResult> Unbind<T, T1, T2, TResult>(this Func<T1, T2, TResult> func)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, TResult> | func | The delegate to unbind. |
Returns
Type | Description |
---|---|
Func<T, T1, T2, TResult> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, T3, T4>(Action<T1, T2, T3, T4>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Action<T, T1, T2, T3, T4> Unbind<T, T1, T2, T3, T4>(this Action<T1, T2, T3, T4> action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4> | action | The delegate to unbind. |
Returns
Type | Description |
---|---|
Action<T, T1, T2, T3, T4> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
T3 | The type of the third explicit parameter. |
T4 | The type of the fourth explicit parameter. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, T3, TResult>(Func<T1, T2, T3, TResult>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Func<T, T1, T2, T3, TResult> Unbind<T, T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> func)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, TResult> | func | The delegate to unbind. |
Returns
Type | Description |
---|---|
Func<T, T1, T2, T3, TResult> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
T3 | The type of the third explicit parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Action<T, T1, T2, T3, T4, T5> Unbind<T, T1, T2, T3, T4, T5>(this Action<T1, T2, T3, T4, T5> action)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5> | action | The delegate to unbind. |
Returns
Type | Description |
---|---|
Action<T, T1, T2, T3, T4, T5> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
T3 | The type of the third explicit parameter. |
T4 | The type of the fourth explicit parameter. |
T5 | The type of the fifth explicit parameter. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Func<T, T1, T2, T3, T4, TResult> Unbind<T, T1, T2, T3, T4, TResult>(this Func<T1, T2, T3, T4, TResult> func)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, TResult> | func | The delegate to unbind. |
Returns
Type | Description |
---|---|
Func<T, T1, T2, T3, T4, TResult> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
T3 | The type of the third explicit parameter. |
T4 | The type of the fourth explicit parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |
Unbind<T, T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult>)
Converts implicitly bound delegate into its unbound version.
Declaration
public static Func<T, T1, T2, T3, T4, T5, TResult> Unbind<T, T1, T2, T3, T4, T5, TResult>(this Func<T1, T2, T3, T4, T5, TResult> func)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Func<T1, T2, T3, T4, T5, TResult> | func | The delegate to unbind. |
Returns
Type | Description |
---|---|
Func<T, T1, T2, T3, T4, T5, TResult> | Unbound version of the delegate. |
Type Parameters
Name | Description |
---|---|
T | The expected type of Target. |
T1 | The type of the first explicit parameter. |
T2 | The type of the second explicit parameter. |
T3 | The type of the third explicit parameter. |
T4 | The type of the fourth explicit parameter. |
T5 | The type of the fifth explicit parameter. |
TResult | The type of the return value of the method that the delegate encapsulates. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Target of |