public class JCDelegate extends Object
Pass an instance of this class (or a subclass) to CLR methods that expect a
delegate parameter. When the CLR invokes the delegate, the bridge calls
DelegateInvoked(Object...) and marshals the return value back to the CLR.
The CLR delegate type is identified either by its fully qualified name
(JCDelegate(String)) or by a pre-resolved JCType handle
(JCDelegate(JCType)).
Override DelegateInvoked(Object...) to provide the delegate body.
The default implementation returns null, which the CLR receives as the
default value for the delegate's return type.
For CLR delegates with a void return type, use JCVoidDelegate
instead.
See also: JCOReflector for usage examples.
| Constructor and Description |
|---|
JCDelegate(JCType delegateType)
Constructs a
JCDelegate from a pre-resolved JCType handle. |
JCDelegate(String delegateTypeName)
Constructs a
JCDelegate identified by the fully qualified CLR delegate
type name. |
| Modifier and Type | Method and Description |
|---|---|
Object |
DelegateInvoked(Object... args)
Called by the bridge when the CLR invokes this delegate.
|
JCType |
getDelegateType()
Returns the pre-resolved CLR delegate type handle, or
null if this
instance was constructed with a type name string. |
String |
getDelegateTypeName()
Returns the fully qualified CLR delegate type name, or
null if this
instance was constructed with a JCType handle. |
public JCDelegate(String delegateTypeName)
JCDelegate identified by the fully qualified CLR delegate
type name. The name is resolved by the bridge when the delegate is passed to a
CLR method.delegateTypeName - the fully qualified CLR delegate type name,
e.g. "System.Func`2[System.String,System.Int32]".public JCDelegate(JCType delegateType)
JCDelegate from a pre-resolved JCType handle.
Use this overload when the delegate type has already been resolved via
JCOBridge.GetType(String) to avoid redundant type lookups.delegateType - the pre-resolved CLR delegate type handle.public String getDelegateTypeName()
null if this
instance was constructed with a JCType handle.public JCType getDelegateType()
null if this
instance was constructed with a type name string.JCType handle for the CLR delegate type.public Object DelegateInvoked(Object... args)
Override this method to provide the delegate body. The returned value is
marshalled back to the CLR as the delegate return value. The default
implementation returns null.
args - the arguments passed by the CLR caller, in the order and types
declared by the CLR delegate signature.String, or a JCObject compatible with the delegate
return type. null maps to the CLR default for the return type.