Show / Hide Table of Contents

Class DelegateHelpers

Represents various extensions of delegates.

Inheritance
Object
DelegateHelpers
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class DelegateHelpers : object

Methods

| Improve this Doc View Source

Bind<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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Bind<T, R>(Func<T, R>, T)

Produces delegate which first parameter is implicitly bound to the given object.

Declaration
public static Func<R> Bind<T, R>(this Func<T, R> func, T obj)

    where T : class
Parameters
Type Name Description
DotNext.Func<T, R> 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
DotNext.Func<R>

The delegate targeting the specified object.

Type Parameters
Name Description
T

The type of the first parameter to bind.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Bind<T1, T2, R>(Func<T1, T2, R>, T1)

Produces delegate which first parameter is implicitly bound to the given object.

Declaration
public static Func<T2, R> Bind<T1, T2, R>(this Func<T1, T2, R> func, T1 obj)

    where T1 : class
Parameters
Type Name Description
DotNext.Func<T1, T2, R> 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
DotNext.Func<T2, R>

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.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Bind<T1, T2, T3, R>(Func<T1, T2, T3, R>, T1)

Produces delegate which first parameter is implicitly bound to the given object.

Declaration
public static Func<T2, T3, R> Bind<T1, T2, T3, R>(this Func<T1, T2, T3, R> func, T1 obj)

    where T1 : class
Parameters
Type Name Description
DotNext.Func<T1, T2, T3, R> 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
DotNext.Func<T2, T3, R>

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.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Bind<T1, T2, T3, T4, R>(Func<T1, T2, T3, T4, R>, T1)

Produces delegate which first parameter is implicitly bound to the given object.

Declaration
public static Func<T2, T3, T4, R> Bind<T1, T2, T3, T4, R>(this Func<T1, T2, T3, T4, R> func, T1 obj)

    where T1 : class
Parameters
Type Name Description
DotNext.Func<T1, T2, T3, T4, R> 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
DotNext.Func<T2, T3, T4, R>

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.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

Bind<T1, T2, T3, T4, T5, R>(Func<T1, T2, T3, T4, T5, R>, T1)

Produces delegate which first parameter is implicitly bound to the given object.

Declaration
public static Func<T2, T3, T4, T5, R> Bind<T1, T2, T3, T4, T5, R>(this Func<T1, T2, T3, T4, T5, R> func, T1 obj)

    where T1 : class
Parameters
Type Name Description
DotNext.Func<T1, T2, T3, T4, T5, R> 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
DotNext.Func<T2, T3, T4, T5, R>

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.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

ChangeType<D>(Delegate)

Returns a new delegate of different type which points to the same method as original delegate.

Declaration
public static D ChangeType<D>(this Delegate d)

    where D : Delegate
Parameters
Type Name Description
Delegate d

Delegate to convert.

Returns
Type Description
D

A method wrapped into new delegate type.

Type Parameters
Name Description
D

A new delegate type.

| Improve this Doc View Source

Contravariant<I, O>(EventHandler<I>)

Performs contravariant conversion of actual generic argument specified for type.

Declaration
public static EventHandler<O> Contravariant<I, O>(this EventHandler<I> handler)

    where I : class where O : class, I
Parameters
Type Name Description
EventHandler<I> handler

The handler to convert.

Returns
Type Description
EventHandler<O>

The delegate referencing the same method as original delegate.

Type Parameters
Name Description
I

Input type of the delegate.

O

A subtype of I.

Remarks

Generic parameter of delegate 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.

| Improve this Doc View Source

CreateClosedDelegateFactory<D>(Expression<D>)

Creates a factory for closed delegates.

Declaration
public static Func<object, D> CreateClosedDelegateFactory<D>(Expression<D> expression)

    where D : Delegate
Parameters
Type Name Description
Expression<D> expression

The expression tree containing instance method, property, operator call.

Returns
Type Description
DotNext.Func<Object, D>

The factory of closed delegate.

Type Parameters
Name Description
D

The type of the delegate describing expression tree.

| Improve this Doc View Source

CreateDelegate<D>(MethodInfo, Object)

Creates a delegate of the specified type with the specified target from this method.

Declaration
public static D CreateDelegate<D>(this MethodInfo method, object target = null)

    where D : 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
D

The delegate for the specified method.

Type Parameters
Name Description
D

The type of the delegate to create.

| Improve this Doc View Source

CreateOpenDelegate<D>(Expression<D>)

Creates open delegate for the instance method, property, operator referenced in expression tree.

Declaration
public static D CreateOpenDelegate<D>(Expression<D> expression)

    where D : Delegate
Parameters
Type Name Description
Expression<D> expression

The expression tree containing instance method call.

Returns
Type Description
D

The open delegate.

Type Parameters
Name Description
D

The type of the delegate describing expression tree.

| Improve this Doc View Source

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 .

| Improve this Doc View Source

Unbind<G, T>(Action<T>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Action<G, T> Unbind<G, T>(this Action<T> action)

    where G : class
Parameters
Type Name Description
Action<T> action

The delegate to unbind.

Returns
Type Description
Action<G, T>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

T

The type of the first explicit parameter.

| Improve this Doc View Source

Unbind<T, R>(Func<R>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Func<T, R> Unbind<T, R>(this Func<R> func)

    where T : class
Parameters
Type Name Description
DotNext.Func<R> func

The delegate to unbind.

Returns
Type Description
DotNext.Func<T, R>

Unbound version of the delegate.

Type Parameters
Name Description
T

The expected type of .

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

Unbind<G, T1, T2>(Action<T1, T2>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Action<G, T1, T2> Unbind<G, T1, T2>(this Action<T1, T2> action)

    where G : class
Parameters
Type Name Description
Action<T1, T2> action

The delegate to unbind.

Returns
Type Description
Action<G, T1, T2>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

T1

The type of the first explicit parameter.

T2

The type of the second explicit parameter.

| Improve this Doc View Source

Unbind<G, T, R>(Func<T, R>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Func<G, T, R> Unbind<G, T, R>(this Func<T, R> func)

    where G : class
Parameters
Type Name Description
DotNext.Func<T, R> func

The delegate to unbind.

Returns
Type Description
DotNext.Func<G, T, R>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

T

The type of the first explicit parameter.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

Unbind<G, T1, T2, T3>(Action<T1, T2, T3>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Action<G, T1, T2, T3> Unbind<G, T1, T2, T3>(this Action<T1, T2, T3> action)

    where G : class
Parameters
Type Name Description
Action<T1, T2, T3> action

The delegate to unbind.

Returns
Type Description
Action<G, T1, T2, T3>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

T1

The type of the first explicit parameter.

T2

The type of the second explicit parameter.

T3

The type of the third explicit parameter.

| Improve this Doc View Source

Unbind<G, T1, T2, R>(Func<T1, T2, R>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Func<G, T1, T2, R> Unbind<G, T1, T2, R>(this Func<T1, T2, R> func)

    where G : class
Parameters
Type Name Description
DotNext.Func<T1, T2, R> func

The delegate to unbind.

Returns
Type Description
DotNext.Func<G, T1, T2, R>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

T1

The type of the first explicit parameter.

T2

The type of the second explicit parameter.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

Unbind<G, T1, T2, T3, T4>(Action<T1, T2, T3, T4>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Action<G, T1, T2, T3, T4> Unbind<G, T1, T2, T3, T4>(this Action<T1, T2, T3, T4> action)

    where G : class
Parameters
Type Name Description
Action<T1, T2, T3, T4> action

The delegate to unbind.

Returns
Type Description
Action<G, T1, T2, T3, T4>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

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.

| Improve this Doc View Source

Unbind<G, T1, T2, T3, R>(Func<T1, T2, T3, R>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Func<G, T1, T2, T3, R> Unbind<G, T1, T2, T3, R>(this Func<T1, T2, T3, R> func)

    where G : class
Parameters
Type Name Description
DotNext.Func<T1, T2, T3, R> func

The delegate to unbind.

Returns
Type Description
DotNext.Func<G, T1, T2, T3, R>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

T1

The type of the first explicit parameter.

T2

The type of the second explicit parameter.

T3

The type of the third explicit parameter.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

Unbind<G, T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Action<G, T1, T2, T3, T4, T5> Unbind<G, T1, T2, T3, T4, T5>(this Action<T1, T2, T3, T4, T5> action)

    where G : class
Parameters
Type Name Description
Action<T1, T2, T3, T4, T5> action

The delegate to unbind.

Returns
Type Description
Action<G, T1, T2, T3, T4, T5>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

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.

| Improve this Doc View Source

Unbind<G, T1, T2, T3, T4, R>(Func<T1, T2, T3, T4, R>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Func<G, T1, T2, T3, T4, R> Unbind<G, T1, T2, T3, T4, R>(this Func<T1, T2, T3, T4, R> func)

    where G : class
Parameters
Type Name Description
DotNext.Func<T1, T2, T3, T4, R> func

The delegate to unbind.

Returns
Type Description
DotNext.Func<G, T1, T2, T3, T4, R>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

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.

R

The type of the return value of the method that the delegate encapsulates.

| Improve this Doc View Source

Unbind<G, T1, T2, T3, T4, T5, R>(Func<T1, T2, T3, T4, T5, R>)

Converts implicitly bound delegate into its unbound version.

Declaration
public static Func<G, T1, T2, T3, T4, T5, R> Unbind<G, T1, T2, T3, T4, T5, R>(this Func<T1, T2, T3, T4, T5, R> func)

    where G : class
Parameters
Type Name Description
DotNext.Func<T1, T2, T3, T4, T5, R> func

The delegate to unbind.

Returns
Type Description
DotNext.Func<G, T1, T2, T3, T4, T5, R>

Unbound version of the delegate.

Type Parameters
Name Description
G

The expected type of .

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.

R

The type of the return value of the method that the delegate encapsulates.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX