C# Class DeftTech.DuckTyping.DelegateDuckProxyType

Class that performs the generation of duck proxy types for forwarding delegate calls.
Exibir arquivo Open project: deftflux/DuckTyping Class Usage Examples

Public Methods

Method Description
CanProxy ( ) : bool

Determines whether a proxy can be generated for the types given in the constructor.

DelegateDuckProxyType ( Type toDelegateType, Type fromDelegateType ) : System

Constructs an object.

Prepare ( ) : void

Prepares by generating the proxy type for the types given in the constructor.

WrapDuck ( Delegate duck ) : Delegate

Calls the static WrapDuck method of the generated proxy type to initialize a new instance of the proxy type with a given duck delegate and return a delegate to its invoke method.

Private Methods

Method Description
GenerateProxyType ( ) : void

If a proxy type has not been generated yet, generates a proxy type that defines a method matching the method signature of the to delegate type given in the constructor which forwards calls to a delegate of the from type given in the constructor.

GetParameterTypes ( ParameterInfo parameters ) : System.Type[]

Utility to create an array of parameter types from an array of parameters.

ImplementInvokeMethod ( TypeBuilder proxyType, FieldInfo duckDelegateField ) : MethodBuilder

Implements the method of the proxy type that invokes the delegate given in its constructor.

Method Details

CanProxy() public method

Determines whether a proxy can be generated for the types given in the constructor.
public CanProxy ( ) : bool
return bool

DelegateDuckProxyType() public method

Constructs an object.
public DelegateDuckProxyType ( Type toDelegateType, Type fromDelegateType ) : System
toDelegateType System.Type Type to be casted to.
fromDelegateType System.Type Type of delegate to be casted.
return System

Prepare() public method

Prepares by generating the proxy type for the types given in the constructor.
public Prepare ( ) : void
return void

WrapDuck() public method

Calls the static WrapDuck method of the generated proxy type to initialize a new instance of the proxy type with a given duck delegate and return a delegate to its invoke method.
public WrapDuck ( Delegate duck ) : Delegate
duck System.Delegate Duck delegate that the new proxy object should forward calls to.
return System.Delegate