Table of Contents

Class DelegateHelper

Namespace
Ecng.Common
Assembly
Ecng.Common.dll

Provides helper methods for working with delegates.

public static class DelegateHelper
Inheritance
DelegateHelper
Inherited Members

Methods

AddDelegate<TDelegate>(TDelegate, TDelegate)

Combines two delegates of the same type.

public static TDelegate AddDelegate<TDelegate>(this TDelegate source, TDelegate value)

Parameters

source TDelegate

The source delegate.

value TDelegate

The delegate to combine with the source delegate.

Returns

TDelegate

A combined delegate of type TDelegate.

Type Parameters

TDelegate

The type of the delegate.

CreateDelegate<TDelegate>(MethodInfo)

Creates a delegate of type TDelegate for the specified method.

public static TDelegate CreateDelegate<TDelegate>(this MethodInfo method)

Parameters

method MethodInfo

The method information.

Returns

TDelegate

A delegate of type TDelegate.

Type Parameters

TDelegate

The type of delegate to create.

CreateDelegate<TInstance, TDelegate>(MethodInfo, TInstance)

Creates a delegate of type TDelegate for the specified method and instance.

public static TDelegate CreateDelegate<TInstance, TDelegate>(this MethodInfo method, TInstance instance)

Parameters

method MethodInfo

The method information.

instance TInstance

The instance on which the method is invoked.

Returns

TDelegate

A delegate of type TDelegate bound to the specified instance.

Type Parameters

TInstance

The type of the instance.

TDelegate

The type of delegate to create.

Do(Action, Action<Exception>)

Executes the specified action and handles any exception using the provided error action.

public static void Do(this Action action, Action<Exception> error)

Parameters

action Action

The action to execute.

error Action<Exception>

The action to handle exceptions.

Exceptions

ArgumentNullException

Thrown when action or error is null.

DoAsync(Action, Action<Exception>)

Executes the specified action asynchronously and handles any exception using the provided error action.

public static void DoAsync(this Action action, Action<Exception> error)

Parameters

action Action

The action to execute asynchronously.

error Action<Exception>

The action to handle exceptions.

Exceptions

ArgumentNullException

Thrown when action or error is null.

GetInvocationList<TDelegate>(TDelegate)

Returns an enumerable collection of delegates from the delegate's invocation list.

public static IEnumerable<TDelegate> GetInvocationList<TDelegate>(this TDelegate @delegate)

Parameters

delegate TDelegate

The delegate whose invocation list is retrieved.

Returns

IEnumerable<TDelegate>

An IEnumerable of TDelegate representing the invocation list.

Type Parameters

TDelegate

The type of the delegate.

Invoke(PropertyChangedEventHandler, object, string)

Invokes the PropertyChangedEventHandler with the specified sender and property name.

public static void Invoke(this PropertyChangedEventHandler handler, object sender, string name)

Parameters

handler PropertyChangedEventHandler

The PropertyChangedEventHandler to invoke.

sender object

The sender object.

name string

The name of the property that changed.

Invoke(PropertyChangingEventHandler, object, string)

Invokes the PropertyChangingEventHandler with the specified sender and property name.

public static void Invoke(this PropertyChangingEventHandler handler, object sender, string name)

Parameters

handler PropertyChangingEventHandler

The PropertyChangingEventHandler to invoke.

sender object

The sender object.

name string

The name of the property that is changing.

RemoveAllDelegates<TDelegate>(TDelegate)

Removes all invocation entries from the delegate.

public static void RemoveAllDelegates<TDelegate>(this TDelegate source)

Parameters

source TDelegate

The delegate from which all delegates are removed.

Type Parameters

TDelegate

The type of the delegate.

RemoveDelegate<TDelegate>(TDelegate, TDelegate)

Removes the specified delegate from the source delegate.

public static TDelegate RemoveDelegate<TDelegate>(this TDelegate source, TDelegate value)

Parameters

source TDelegate

The source delegate.

value TDelegate

The delegate to remove from the source.

Returns

TDelegate

The resulting delegate of type TDelegate after removal.

Type Parameters

TDelegate

The type of the delegate.