Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Delegate

Assembly: System.Runtime

Inheritance: object → Delegate

Implemented Interfaces

Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class.

Properties

public bool
HasSingleTarget
Gets a value that indicates whether the <see cref="T:System.Delegate" /> has a single invocation target.
public MethodInfo
Method
Gets the method represented by the delegate.
public object
Target
Gets the class instance on which the current delegate invokes the instance method.

Methods

public object
Clone​()
Creates a shallow copy of the delegate.
Returns A shallow copy of the delegate.
public static delegate
Combine​(delegate a, delegate b)
Concatenates the invocation lists of two delegates.
Returns A new delegate with an invocation list that concatenates the invocation lists of <paramref name="a" /> and <paramref name="b" /> in that order. Returns <paramref name="a" /> if <paramref name="b" /> is <see langword="null" /> , returns <paramref name="b" /> if <paramref name="a" /> is a null reference, and returns a null reference if both <paramref name="a" /> and <paramref name="b" /> are null references.
a The delegate whose invocation list comes first.
b The delegate whose invocation list comes last.
public static delegate
Combine​(delegate[] delegates)
Concatenates the invocation lists of an array of delegates.
Returns A new delegate with an invocation list that concatenates the invocation lists of the delegates in the <paramref name="delegates" /> array. Returns <see langword="null" /> if <paramref name="delegates" /> is <see langword="null" /> , if <paramref name="delegates" /> contains zero elements, or if every entry in <paramref name="delegates" /> is <see langword="null" /> .
delegates The array of delegates to combine.
public static delegate
Combine​(ReadOnlySpan<​delegate> delegates)
Concatenates the invocation lists of an span of delegates.
Returns A new delegate with an invocation list that concatenates the invocation lists of the delegates in the <paramref name="delegates" /> span. Returns <see langword="null" /> if <paramref name="delegates" /> is <see langword="null" /> , if <paramref name="delegates" /> contains zero elements, or if every entry in <paramref name="delegates" /> is <see langword="null" /> .
delegates The span of delegates to combine.
protected delegate
CombineImpl​(delegate d)
Concatenates the invocation lists of the specified multicast (combinable) delegate and the current multicast (combinable) delegate.
Returns A new multicast (combinable) delegate with an invocation list that concatenates the invocation list of the current multicast (combinable) delegate and the invocation list of <paramref name="d" /> , or the current multicast (combinable) delegate if <paramref name="d" /> is <see langword="null" /> .
d The multicast (combinable) delegate whose invocation list to append to the end of the invocation list of the current multicast (combinable) delegate.
public static delegate
CreateDelegate​(Type type, object firstArgument, MethodInfo method)
Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument.
Returns A delegate of the specified type that represents the specified static or instance method.
type The <see cref="T:System.Type" /> of delegate to create.
firstArgument The object to which the delegate is bound, or <see langword="null" /> to treat <paramref name="method" /> as <see langword="static" /> ( <see langword="Shared" /> in Visual Basic).
method The <see cref="T:System.Reflection.MethodInfo" /> describing the static or instance method the delegate is to represent.
public static delegate
CreateDelegate​(Type type, object firstArgument, MethodInfo method, bool throwOnBindFailure)
Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument and the specified behavior on failure to bind.
Returns A delegate of the specified type that represents the specified static or instance method, or <see langword="null" /> if <paramref name="throwOnBindFailure" /> is <see langword="false" /> and the delegate cannot be bound to <paramref name="method" /> .
type A <see cref="T:System.Type" /> representing the type of delegate to create.
firstArgument An <see cref="T:System.Object" /> that is the first argument of the method the delegate represents. For instance methods, it must be compatible with the instance type.
method The <see cref="T:System.Reflection.MethodInfo" /> describing the static or instance method the delegate is to represent.
throwOnBindFailure <see langword="true" /> to throw an exception if <paramref name="method" /> cannot be bound; otherwise, <see langword="false" /> .
public static delegate
CreateDelegate​(Type type, object target, string method)
Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
Returns A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
type The <see cref="T:System.Type" /> of delegate to create.
target The class instance on which <paramref name="method" /> is invoked.
method The name of the instance method that the delegate is to represent.
public static delegate
CreateDelegate​(Type type, object target, string method, bool ignoreCase)
Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance with the specified case-sensitivity.
Returns A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
type The <see cref="T:System.Type" /> of delegate to create.
target The class instance on which <paramref name="method" /> is invoked.
method The name of the instance method that the delegate is to represent.
ignoreCase A Boolean indicating whether to ignore the case when comparing the name of the method.
public static delegate
CreateDelegate​(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure)
Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance, with the specified case-sensitivity and the specified behavior on failure to bind.
Returns A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
type The <see cref="T:System.Type" /> of delegate to create.
target The class instance on which <paramref name="method" /> is invoked.
method The name of the instance method that the delegate is to represent.
ignoreCase A Boolean indicating whether to ignore the case when comparing the name of the method.
throwOnBindFailure <see langword="true" /> to throw an exception if <paramref name="method" /> cannot be bound; otherwise, <see langword="false" /> .
public static delegate
CreateDelegate​(Type type, MethodInfo method)
Creates a delegate of the specified type to represent the specified method.
Returns A delegate of the specified type to represent the specified method.
type The <see cref="T:System.Type" /> of delegate to create.
method The <see cref="T:System.Reflection.MethodInfo" /> describing the static or instance method the delegate is to represent.
public static delegate
CreateDelegate​(Type type, MethodInfo method, bool throwOnBindFailure)
Creates a delegate of the specified type to represent the specified static method, with the specified behavior on failure to bind.
Returns A delegate of the specified type to represent the specified static method.
type The <see cref="T:System.Type" /> of delegate to create.
method The <see cref="T:System.Reflection.MethodInfo" /> describing the static or instance method the delegate is to represent.
throwOnBindFailure <see langword="true" /> to throw an exception if <paramref name="method" /> cannot be bound; otherwise, <see langword="false" /> .
public static delegate
CreateDelegate​(Type type, Type target, string method)
Creates a delegate of the specified type that represents the specified static method of the specified class.
Returns A delegate of the specified type that represents the specified static method of the specified class.
type The <see cref="T:System.Type" /> of delegate to create.
target The <see cref="T:System.Type" /> representing the class that implements <paramref name="method" /> .
method The name of the static method that the delegate is to represent.
public static delegate
CreateDelegate​(Type type, Type target, string method, bool ignoreCase)
Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity.
Returns A delegate of the specified type that represents the specified static method of the specified class.
type The <see cref="T:System.Type" /> of delegate to create.
target The <see cref="T:System.Type" /> representing the class that implements <paramref name="method" /> .
method The name of the static method that the delegate is to represent.
ignoreCase A Boolean indicating whether to ignore the case when comparing the name of the method.
public static delegate
CreateDelegate​(Type type, Type target, string method, bool ignoreCase, bool throwOnBindFailure)
Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity and the specified behavior on failure to bind.
Returns A delegate of the specified type that represents the specified static method of the specified class.
type The <see cref="T:System.Type" /> of delegate to create.
target The <see cref="T:System.Type" /> representing the class that implements <paramref name="method" /> .
method The name of the static method that the delegate is to represent.
ignoreCase A Boolean indicating whether to ignore the case when comparing the name of the method.
throwOnBindFailure <see langword="true" /> to throw an exception if <paramref name="method" /> cannot be bound; otherwise, <see langword="false" /> .
public object
DynamicInvoke​(object[] args)
Dynamically invokes (late-bound) the method represented by the current delegate.
Returns The object returned by the method represented by the delegate.
args An array of objects that are the arguments to pass to the method represented by the current delegate. -or- <see langword="null" /> , if the method represented by the current delegate does not require arguments.
protected object
DynamicInvokeImpl​(object[] args)
Dynamically invokes (late-bound) the method represented by the current delegate.
Returns The object returned by the method represented by the delegate.
args An array of objects that are the arguments to pass to the method represented by the current delegate. -or- <see langword="null" /> , if the method represented by the current delegate does not require arguments.
public static InvocationListEnumerator<​TDelegate>
EnumerateInvocationList​(TDelegate? d)
Gets an enumerator for the invocation targets of this delegate.
Returns A <see cref="T:System.Delegate.InvocationListEnumerator`1" /> that follows the IEnumerable pattern and thus can be used in a C# 'foreach' statement to retrieve the invocation targets of this delegate without allocations. The method returns an empty enumerator for <see langword="null" /> delegate.
d The delegate being enumerated.
public bool
Equals​(object obj)
Determines whether the specified object and the current delegate are of the same type and share the same targets, methods, and invocation list.
Returns <see langword="true" /> if <paramref name="obj" /> and the current delegate have the same targets, methods, and invocation list; otherwise, <see langword="false" /> .
obj The object to compare with the current delegate.
public int
GetHashCode​()
Returns a hash code for the delegate.
Returns A hash code for the delegate.
public delegate[]
GetInvocationList​()
Returns the invocation list of the delegate.
Returns An array of delegates representing the invocation list of the current delegate.
protected MethodInfo
GetMethodImpl​()
Gets the method represented by the current delegate.
Returns A <see cref="T:System.Reflection.MethodInfo" /> describing the method represented by the current delegate.
public void
GetObjectData​(SerializationInfo info, StreamingContext context)
Not supported.
info Not supported.
context Not supported.
public static delegate
Remove​(delegate source, delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate.
Returns A new delegate with an invocation list formed by taking the invocation list of <paramref name="source" /> and removing the last occurrence of the invocation list of <paramref name="value" /> , if the invocation list of <paramref name="value" /> is found within the invocation list of <paramref name="source" /> . Returns <paramref name="source" /> if <paramref name="value" /> is <see langword="null" /> or if the invocation list of <paramref name="value" /> is not found within the invocation list of <paramref name="source" /> . Returns a null reference if the invocation list of <paramref name="value" /> is equal to the invocation list of <paramref name="source" /> or if <paramref name="source" /> is a null reference.
source The delegate from which to remove the invocation list of <paramref name="value" /> .
value The delegate that supplies the invocation list to remove from the invocation list of <paramref name="source" /> .
public static delegate
RemoveAll​(delegate source, delegate value)
Removes all occurrences of the invocation list of a delegate from the invocation list of another delegate.
Returns A new delegate with an invocation list formed by taking the invocation list of <paramref name="source" /> and removing all occurrences of the invocation list of <paramref name="value" /> , if the invocation list of <paramref name="value" /> is found within the invocation list of <paramref name="source" /> . Returns <paramref name="source" /> if <paramref name="value" /> is <see langword="null" /> or if the invocation list of <paramref name="value" /> is not found within the invocation list of <paramref name="source" /> . Returns a null reference if the invocation list of <paramref name="value" /> is equal to the invocation list of <paramref name="source" /> , if <paramref name="source" /> contains only a series of invocation lists that are equal to the invocation list of <paramref name="value" /> , or if <paramref name="source" /> is a null reference.
source The delegate from which to remove the invocation list of <paramref name="value" /> .
value The delegate that supplies the invocation list to remove from the invocation list of <paramref name="source" /> .
protected delegate
RemoveImpl​(delegate d)
Removes the invocation list of a delegate from the invocation list of another delegate.
Returns A new delegate with an invocation list formed by taking the invocation list of the current delegate and removing the invocation list of <paramref name="d" /> , if the invocation list of <paramref name="d" /> is found within the current delegate's invocation list. Returns the current delegate if <paramref name="d" /> is <see langword="null" /> or if the invocation list of <paramref name="d" /> is not found within the current delegate's invocation list. Returns <see langword="null" /> if the invocation list of <paramref name="d" /> is equal to the current delegate's invocation list.
d The delegate that supplies the invocation list to remove from the invocation list of the current delegate.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.