14 [__DynamicallyInvokable]
18 internal object _target;
21 internal object _methodBase;
24 internal IntPtr _methodPtr;
27 internal IntPtr _methodPtrAux;
32 [__DynamicallyInvokable]
35 [__DynamicallyInvokable]
44 [__DynamicallyInvokable]
47 [__DynamicallyInvokable]
61 [SecuritySafeCritical]
62 protected Delegate(
object target,
string method)
72 if (!BindToMethodName(target, (RuntimeType)target.GetType(), method, (DelegateBindingFlags)10))
87 [SecuritySafeCritical]
102 RuntimeType runtimeType = target as RuntimeType;
103 if (runtimeType ==
null)
107 BindToMethodName(
null, runtimeType, method, (DelegateBindingFlags)37);
121 [__DynamicallyInvokable]
134 [SecuritySafeCritical]
137 RuntimeMethodInfo runtimeMethodInfo = (RuntimeMethodInfo)RuntimeType.GetMethodBase(methodHandle:
new RuntimeMethodHandleInternal(GetInvokeMethod()), reflectedType: (RuntimeType)GetType());
138 return runtimeMethodInfo.UnsafeInvoke(
this,
BindingFlags.Default,
null, args,
null);
146 [SecuritySafeCritical]
147 [__DynamicallyInvokable]
150 if (obj ==
null || !InternalEqualTypes(
this, obj))
155 if (_target == @delegate._target && _methodPtr == @delegate._methodPtr && _methodPtrAux == @delegate._methodPtrAux)
159 if (_methodPtrAux.IsNull())
161 if (!@delegate._methodPtrAux.IsNull())
165 if (_target != @delegate._target)
172 if (@delegate._methodPtrAux.IsNull())
176 if (_methodPtrAux == @delegate._methodPtrAux)
181 if (_methodBase ==
null || @delegate._methodBase ==
null || !(_methodBase is
MethodInfo) || !(@delegate._methodBase is
MethodInfo))
183 return InternalEqualMethodHandles(
this, @delegate);
185 return _methodBase.Equals(@delegate._methodBase);
190 [__DynamicallyInvokable]
193 return GetType().GetHashCode();
201 [__DynamicallyInvokable]
204 if ((
object)a ==
null)
216 [__DynamicallyInvokable]
219 if (delegates ==
null || delegates.Length == 0)
224 for (
int i = 1; i < delegates.Length; i++)
226 @delegate =
Combine(@delegate, delegates[i]);
233 [__DynamicallyInvokable]
245 [SecuritySafeCritical]
248 if (_methodBase ==
null || !(_methodBase is
MethodInfo))
250 IRuntimeMethodInfo runtimeMethodInfo = FindMethodHandle();
254 if (_methodPtrAux == (
IntPtr)0)
262 runtimeType = (type as RuntimeType);
270 MethodInfo method = GetType().GetMethod(
"Invoke");
274 _methodBase = (
MethodInfo)RuntimeType.GetMethodBase(runtimeType, runtimeMethodInfo);
285 [SecuritySafeCritical]
286 [__DynamicallyInvokable]
289 if ((
object)source ==
null)
293 if ((
object)value ==
null)
297 if (!InternalEqualTypes(source, value))
310 [__DynamicallyInvokable]
317 source =
Remove(source, value);
319 while (@delegate != source);
349 return MemberwiseClone();
370 return CreateDelegate(type, target, method, ignoreCase:
false, throwOnBindFailure:
true);
392 return CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure:
true);
414 [SecuritySafeCritical]
429 RuntimeType runtimeType = type as RuntimeType;
430 if (runtimeType ==
null)
434 if (!runtimeType.IsDelegate())
438 Delegate @delegate = InternalAlloc(runtimeType);
439 if (!@delegate.BindToMethodName(target, (RuntimeType)target.GetType(), method, (DelegateBindingFlags)(0x1A | (ignoreCase ? 32 : 0))))
441 if (throwOnBindFailure)
470 return CreateDelegate(type, target, method, ignoreCase:
false, throwOnBindFailure:
true);
494 return CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure:
true);
518 [SecuritySafeCritical]
537 RuntimeType runtimeType = type as RuntimeType;
538 RuntimeType runtimeType2 = target as RuntimeType;
539 if (runtimeType ==
null)
543 if (runtimeType2 ==
null)
547 if (!runtimeType.IsDelegate())
551 Delegate @delegate = InternalAlloc(runtimeType);
552 if (!@delegate.BindToMethodName(
null, runtimeType2, method, (DelegateBindingFlags)(5 | (ignoreCase ? 32 : 0))))
554 if (throwOnBindFailure)
580 [SecuritySafeCritical]
591 RuntimeType runtimeType = type as RuntimeType;
592 if (runtimeType ==
null)
596 RuntimeMethodInfo runtimeMethodInfo = method as RuntimeMethodInfo;
597 if (runtimeMethodInfo ==
null)
601 if (!runtimeType.IsDelegate())
605 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
606 Delegate @delegate = CreateDelegateInternal(runtimeType, runtimeMethodInfo,
null, (DelegateBindingFlags)132, ref stackMark);
607 if ((
object)@delegate ==
null && throwOnBindFailure)
629 [__DynamicallyInvokable]
632 return CreateDelegate(type, firstArgument, method, throwOnBindFailure:
true);
653 [SecuritySafeCritical]
664 RuntimeType runtimeType = type as RuntimeType;
665 if (runtimeType ==
null)
669 RuntimeMethodInfo runtimeMethodInfo = method as RuntimeMethodInfo;
670 if (runtimeMethodInfo ==
null)
674 if (!runtimeType.IsDelegate())
678 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
679 Delegate @delegate = CreateDelegateInternal(runtimeType, runtimeMethodInfo, firstArgument, DelegateBindingFlags.RelaxedSignature, ref stackMark);
680 if ((
object)@delegate ==
null && throwOnBindFailure)
692 [__DynamicallyInvokable]
695 return d1?.
Equals(d2) ?? ((object)d2 ==
null);
703 [__DynamicallyInvokable]
706 if ((
object)d1 ==
null)
708 return (
object)d2 !=
null;
730 if (method.IsNullHandle())
732 throw new ArgumentNullException(
"method");
734 RuntimeType runtimeType = type as RuntimeType;
735 if (runtimeType ==
null)
737 throw new ArgumentException(Environment.GetResourceString(
"Argument_MustBeRuntimeType"),
"type");
739 if (!runtimeType.IsDelegate())
741 throw new ArgumentException(Environment.GetResourceString(
"Arg_MustBeDelegate"),
"type");
743 Delegate @delegate = InternalAlloc(runtimeType);
744 if (!@delegate.BindToMethodInfo(target, method.GetMethodInfo(), RuntimeMethodHandle.GetDeclaringType(method.GetMethodInfo()), (DelegateBindingFlags)192))
746 throw new ArgumentException(Environment.GetResourceString(
"Arg_DlgtTargMeth"));
752 internal static Delegate CreateDelegateNoSecurityCheck(RuntimeType type,
object firstArgument,
MethodInfo method)
756 throw new ArgumentNullException(
"type");
760 throw new ArgumentNullException(
"method");
762 RuntimeMethodInfo runtimeMethodInfo = method as RuntimeMethodInfo;
763 if (runtimeMethodInfo ==
null)
765 throw new ArgumentException(Environment.GetResourceString(
"Argument_MustBeRuntimeMethodInfo"),
"method");
767 if (!type.IsDelegate())
769 throw new ArgumentException(Environment.GetResourceString(
"Arg_MustBeDelegate"),
"type");
771 Delegate @delegate = UnsafeCreateDelegate(type, runtimeMethodInfo, firstArgument, (DelegateBindingFlags)192);
772 if ((
object)@delegate ==
null)
774 throw new ArgumentException(Environment.GetResourceString(
"Arg_DlgtTargMeth"));
794 [__DynamicallyInvokable]
800 [SecuritySafeCritical]
801 internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod,
object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark)
803 bool flag = (rtMethod.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN;
804 bool flag2 = (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN;
807 RuntimeAssembly executingAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
808 if (executingAssembly !=
null && !executingAssembly.IsSafeForReflection())
813 return UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags);
817 internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod,
object firstArgument, DelegateBindingFlags flags)
819 Delegate @delegate = InternalAlloc(rtType);
820 if (@delegate.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags))
829 private extern bool BindToMethodName(
object target, RuntimeType methodType,
string method, DelegateBindingFlags flags);
833 private extern bool BindToMethodInfo(
object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags);
837 private static extern MulticastDelegate InternalAlloc(RuntimeType type);
841 internal static extern MulticastDelegate InternalAllocLike(Delegate d);
845 internal static extern bool InternalEqualTypes(
object a,
object b);
849 private extern void DelegateConstruct(
object target, IntPtr slot);
853 internal extern IntPtr GetMulticastInvoke();
857 internal extern IntPtr GetInvokeMethod();
860 internal extern IRuntimeMethodInfo FindMethodHandle();
864 internal static extern bool InternalEqualMethodHandles(Delegate left, Delegate right);
868 internal extern IntPtr AdjustTarget(
object target, IntPtr methodPtr);
872 internal extern IntPtr GetCallStub(IntPtr methodPtr);
874 [SecuritySafeCritical]
875 internal virtual object GetTarget()
877 if (!_methodPtrAux.IsNull())
886 internal static extern bool CompareUnmanagedFunctionPtrs(Delegate d1, Delegate d2);
abstract Type BaseType
Gets the type from which the current T:System.Type directly inherits.
virtual Type GetGenericTypeDefinition()
Returns a T:System.Type object that represents a generic type definition from which the current gener...
MethodAttributes
Specifies flags for method attributes. These flags are defined in the corhdr.h file.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
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...
virtual object Clone()
Creates a shallow copy of the delegate.
virtual Delegate CombineImpl(Delegate d)
Concatenates the invocation lists of the specified multicast (combinable) delegate and the current mu...
Discovers the attributes of a method and provides access to method metadata.
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...
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
object Target
Gets the class instance on which the current delegate invokes the instance method.
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 t...
Represents a type using an internal metadata token.
virtual bool IsGenericType
Gets a value indicating whether the current type is a generic type.
virtual bool ContainsGenericParameters
Gets a value indicating whether the current T:System.Type object has type parameters that have not be...
virtual MethodInfo GetMethodImpl()
Gets the static method represented by the current delegate.
virtual Delegate [] GetInvocationList()
Returns the invocation list of the delegate.
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,...
Describes the source and destination of a given serialized stream, and provides an additional caller-...
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
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...
Provides information about, and means to manipulate, the current environment and platform....
static Delegate CreateDelegate(Type type, object firstArgument, MethodInfo method)
Creates a delegate of the specified type that represents the specified static or instance method,...
T:System.RuntimeMethodHandle is a handle to the internal metadata representation of a method.
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Not supported.
static bool operator !=(Delegate d1, Delegate d2)
Determines whether the specified delegates are not equal.
virtual Delegate RemoveImpl(Delegate d)
Removes the invocation list of a delegate from the invocation list of another delegate.
object DynamicInvoke(params object[] args)
Dynamically invokes (late-bound) the method represented by the current delegate.
override int GetHashCode()
Returns a hash code for the delegate.
A platform-specific type that is used to represent a pointer or a handle.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
virtual object DynamicInvokeImpl(object[] args)
Dynamically invokes (late-bound) the method represented by the current delegate.
Represents type declarations: class types, interface types, array types, value types,...
static Delegate RemoveAll(Delegate source, Delegate value)
Removes all occurrences of the invocation list of a delegate from the invocation list of another dele...
static Delegate CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure)
Creates a delegate of the specified type to represent the specified static method,...
MethodImplOptions
Defines the details of how a method is implemented.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
static Delegate CreateDelegate(Type type, MethodInfo method)
Creates a delegate of the specified type to represent the specified static method.
static bool operator==(Delegate d1, Delegate d2)
Determines whether the specified delegates are equal.
MethodInfo Method
Gets the method represented by the delegate.
The exception that is thrown when one of the arguments provided to a method is not valid.
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 t...
Allows an object to control its own serialization and deserialization.
override bool Equals(object obj)
Determines whether the specified object and the current delegate are of the same type and share the s...
Specifies that the class can be serialized.
virtual Type ParameterType
Gets the Type of this parameter.
The exception that is thrown when a method call is invalid for the object's current state.
static Delegate Combine(params Delegate[] delegates)
Concatenates the invocation lists of an array of delegates.
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
Delegate(Type target, string method)
Initializes a delegate that invokes the specified static method from the specified class.
The exception that is thrown when there is an attempt to combine two delegates based on the T:System....
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Delegate(object target, string method)
Initializes a delegate that invokes the specified instance method on the specified class instance.
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 t...
abstract ParameterInfo [] GetParameters()
When overridden in a derived class, gets the parameters of the specified method or constructor.