internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags) { #if FEATURE_LEGACYNETCF if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) if(rtMethod.IsGenericMethodDefinition) throw new MissingMethodException(rtMethod.DeclaringType.FullName, rtMethod.Name); #endif Delegate d = InternalAlloc(rtType); if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags)) return d; else return null; }
private Delegate CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags, ref StackCrawlMark stackMark) { // Validate the parameters. if (delegateType == null) throw new ArgumentNullException(nameof(delegateType)); Contract.EndContractBlock(); RuntimeType rtType = delegateType as RuntimeType; if (rtType == null) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(delegateType)); if (!rtType.IsDelegate()) throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(delegateType)); Delegate d = Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags, ref stackMark); if (d == null) { throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTargMeth")); } return d; }
internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark) { Contract.Assert((flags & DelegateBindingFlags.SkipSecurityChecks) == 0); #if FEATURE_APPX bool nonW8PMethod = (rtMethod.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0; bool nonW8PType = (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0; if (nonW8PMethod || nonW8PType) { RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (caller != null && !caller.IsSafeForReflection()) throw new InvalidOperationException( Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", nonW8PMethod ? rtMethod.FullName : rtType.FullName)); } #endif return UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags); }
private extern bool BindToMethodInfo(object target, RuntimeMethodHandle method, RuntimeTypeHandle methodType, DelegateBindingFlags flags);
internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags) { Delegate d = InternalAlloc(rtType); if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags)) return d; else return null; }
internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags) { #if FEATURE_LEGACYNETCF if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) { if (rtMethod.IsGenericMethodDefinition) { throw new MissingMethodException(rtMethod.DeclaringType.FullName, rtMethod.Name); } } #endif Delegate d = InternalAlloc(rtType); if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags)) { return(d); } else { return(null); } }
private Delegate CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags, ref StackCrawlMark stackMark) { // Validate the parameters. if (delegateType == null) throw new ArgumentNullException("delegateType"); Contract.EndContractBlock(); RuntimeType rtType = delegateType as RuntimeType; if (rtType == null) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "delegateType"); if (!rtType.IsDelegate()) throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "delegateType"); #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage)) { FrameworkEventSource.Log.BeginMethodInfoCreateDelegate(GetRuntimeType() != null ? GetRuntimeType().GetFullNameForEtw() : "", GetFullNameForEtw(),rtType.GetFullNameForEtw()); } #endif Delegate d = Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags, ref stackMark); if (d == null) { throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTargMeth")); } #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage)) { FrameworkEventSource.Log.EndMethodInfoCreateDelegate(GetRuntimeType() != null ? GetRuntimeType().GetFullNameForEtw() : "", GetFullNameForEtw(),rtType.GetFullNameForEtw()); } #endif return d; }
private Delegate CreateDelegateInternal(Type delegateType, object firstArgument, DelegateBindingFlags bindingFlags) { // Validate the parameters. if (delegateType == null) { throw new ArgumentNullException(nameof(delegateType)); } RuntimeType rtType = delegateType as RuntimeType; if (rtType == null) { throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(delegateType)); } if (!rtType.IsDelegate()) { throw new ArgumentException(SR.Arg_MustBeDelegate, nameof(delegateType)); } Delegate d = Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags); if (d == null) { throw new ArgumentException(SR.Arg_DlgtTargMeth); } return(d); }
internal static Delegate?CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, object?firstArgument, DelegateBindingFlags flags) { Delegate d = InternalAlloc(rtType); if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags)) { return(d); } else { return(null); } }
private extern bool BindToMethodName(Object target, RuntimeType methodType, String method, DelegateBindingFlags flags);
private extern bool BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags);
internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark) { Debug.Assert((flags & DelegateBindingFlags.SkipSecurityChecks) == 0); #if FEATURE_APPX bool nonW8PMethod = (rtMethod.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0; bool nonW8PType = (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0; if (nonW8PMethod || nonW8PType) { RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (caller != null && !caller.IsSafeForReflection()) { throw new InvalidOperationException( Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", nonW8PMethod ? rtMethod.FullName : rtType.FullName)); } } #endif return(UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags)); }
private Delegate CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags, ref StackCrawlMark stackMark) { // Validate the parameters. if (delegateType == null) { throw new ArgumentNullException(nameof(delegateType)); } Contract.EndContractBlock(); RuntimeType rtType = delegateType as RuntimeType; if (rtType == null) { throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(delegateType)); } if (!rtType.IsDelegate()) { throw new ArgumentException(SR.Arg_MustBeDelegate, nameof(delegateType)); } Delegate d = Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags, ref stackMark); if (d == null) { throw new ArgumentException(SR.Arg_DlgtTargMeth); } return(d); }
private extern bool BindToMethodName(object?target, [DynamicallyAccessedMembers(AllMethods)] RuntimeType methodType, string method, DelegateBindingFlags flags);
internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark) { Debug.Assert((flags & DelegateBindingFlags.SkipSecurityChecks) == 0); return(UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags)); }