CSharpUtilities::DelegateCaller Class Reference


Detailed Description

Convenient stand-in for the thread-safe delegate invocation idiom.

For example, instead of invoking a Click event handler in a thread-safe manner by writing:

    EventHandler<EventArgs> threadSafeDelegateCopy = Click;
    if(null != threadSafeDelegateCopy)
    {
       threadSafeDelegateCopy(this, EventArgs.Empty);
    }

It can be invoked equivalently, but more simply using the DelegateCaller as:

    DelegateCaller.Call(Click, this, EventArgs.Empty);

List of all members.

Public Member Functions

  DelegateCaller (Delegate d)
  Construct a DelegateCaller to call the given Delegate d.
object  Call (Object[] args)
  Calls the encapsulated delegate (possibly a multicast delegate) and returns the object returned by the delegate.

Static Public Member Functions

static object  Call (Delegate d, params Object[] args)
  Call the given delegate or event with the given arguments.

Properties

bool  Callable [get]
  Is the encapsulated delegate valid and callable?

Constructor & Destructor Documentation

CSharpUtilities::DelegateCaller::DelegateCaller ( Delegate  d ) [inline]

Construct a DelegateCaller to call the given Delegate d.

Parameters:
d The delegate to safely call.

Member Function Documentation

object CSharpUtilities::DelegateCaller::Call ( Object[]  args ) [inline]

Calls the encapsulated delegate (possibly a multicast delegate) and returns the object returned by the delegate.

Traps any thrown exception.

Parameters:
args Arguments passed to the delegate
Returns:
The delegate's return value.
static object CSharpUtilities::DelegateCaller::Call ( Delegate  d,
params Object[]  args 
) [inline, static]

Call the given delegate or event with the given arguments.

Parameters:
d The delegate to call.
args The C# params modifier is roughly equivalent to the C++ ellipsis (...). It will build the args parameter array from the caller site parameter list. In this case, the arguments must be of the type and in the order expected by the delegate.
Returns:
The delgate's return value.

Property Documentation

bool CSharpUtilities::DelegateCaller::Callable [get]

Is the encapsulated delegate valid and callable?


CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller
CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller CSharpUtilities::DelegateCaller