// // internal implementation details (FCALLS and utilities) // // V2 internal API. internal static Delegate CreateDelegateNoSecurityCheck( Type type, object?target, RuntimeMethodHandle method ) { // Validate the parameters. if (type == null) { throw new ArgumentNullException(nameof(type)); } if (method.IsNullHandle()) { throw new ArgumentNullException(nameof(method)); } if (!(type is RuntimeType rtType)) { throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type)); } if (!rtType.IsDelegate()) { throw new ArgumentException(SR.Arg_MustBeDelegate, nameof(type)); } // Initialize the method... Delegate d = InternalAlloc(rtType); // This is a new internal API added in Whidbey. Currently it's only // used by the dynamic method code to generate a wrapper delegate. // Allow flexible binding options since the target method is // unambiguously provided to us. if ( !d.BindToMethodInfo( target, method.GetMethodInfo(), RuntimeMethodHandle.GetDeclaringType(method.GetMethodInfo()), DelegateBindingFlags.RelaxedSignature ) ) { throw new ArgumentException(SR.Arg_DlgtTargMeth); } return(d); }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) { if (handle.IsNullHandle()) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage)) { FrameworkEventSource.Log.BeginGetMethodFromHandle(); } #endif MethodBase m = RuntimeType.GetMethodBase(handle.GetMethodInfo()); Type declaringType = m.DeclaringType; #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null) { FrameworkEventSource.Log.EndGetMethodFromHandle(declaringType.GetFullNameForEtw(), m.GetFullNameForEtw()); } #endif if (declaringType != null && declaringType.IsGenericType) throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGeneric"), m, declaringType.GetGenericTypeDefinition())); return m; }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType) { if (handle.IsNullHandle()) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo()); }
internal static Delegate CreateDelegate(Type type, object target, RuntimeMethodHandle method) { if (type == null) { throw new ArgumentNullException("type"); } if (method.IsNullHandle()) { throw new ArgumentNullException("method"); } if (!(type is RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); } Type baseType = type.BaseType; if ((baseType == null) || (baseType != typeof(MulticastDelegate))) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); } Delegate delegate2 = InternalAlloc(type.TypeHandle.GetRuntimeType()); if (!delegate2.BindToMethodInfo(target, method.GetMethodInfo(), RuntimeMethodHandle.GetDeclaringType(method.GetMethodInfo()), DelegateBindingFlags.RelaxedSignature)) { throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTargMeth")); } return(delegate2); }
[System.Security.SecurityCritical] // auto-generated internal unsafe static Delegate CreateDelegateNoSecurityCheck(Type type, Object target, RuntimeMethodHandle method) { // Validate the parameters. if (type == null) { throw new ArgumentNullException("type"); } Contract.EndContractBlock(); if (method.IsNullHandle()) { throw new ArgumentNullException("method"); } RuntimeType rtType = type as RuntimeType; if (rtType == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); } if (!rtType.IsDelegate()) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); } // Initialize the method... Delegate d = InternalAlloc(rtType); // This is a new internal API added in Whidbey. Currently it's only // used by the dynamic method code to generate a wrapper delegate. // Allow flexible binding options since the target method is // unambiguously provided to us. // < if (!d.BindToMethodInfo(target, method.GetMethodInfo(), RuntimeMethodHandle.GetDeclaringType(method.GetMethodInfo()), DelegateBindingFlags.RelaxedSignature | DelegateBindingFlags.SkipSecurityChecks)) { throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTargMeth")); } return(d); }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) { if (handle.IsNullHandle()) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); MethodBase m = RuntimeType.GetMethodBase(handle.GetMethodInfo()); Type declaringType = m.DeclaringType; if (declaringType != null && declaringType.IsGenericType) throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGeneric"), m, declaringType.GetGenericTypeDefinition())); return m; }
public int GetTokenFor(RuntimeMethodHandle method) { IRuntimeMethodInfo methodInfo = method.GetMethodInfo(); RuntimeMethodHandleInternal internal2 = methodInfo.Value; if ((methodInfo != null) && !RuntimeMethodHandle.IsDynamicMethod(internal2)) { RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(internal2); if ((declaringType != null) && RuntimeTypeHandle.IsGenericType(declaringType)) { MethodBase methodBase = RuntimeType.GetMethodBase(methodInfo); Type genericTypeDefinition = methodBase.DeclaringType.GetGenericTypeDefinition(); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGenericLcg"), new object[] { methodBase, genericTypeDefinition })); } } this.m_tokens.Add(method); return ((this.m_tokens.Count - 1) | 0x6000000); }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) { if (handle.IsNullHandle()) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); #if MONO MethodBase m = GetMethodFromHandleInternalType (handle.Value, IntPtr.Zero); if (m == null) throw new ArgumentException ("The handle is invalid."); #else MethodBase m = RuntimeType.GetMethodBase(handle.GetMethodInfo()); #endif Type declaringType = m.DeclaringType; if (declaringType != null && declaringType.IsGenericType) throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGeneric"), m, declaringType.GetGenericTypeDefinition())); return m; }
internal static Delegate CreateDelegate(Type type, object target, RuntimeMethodHandle method) { if (type == null) { throw new ArgumentNullException("type"); } if (method.IsNullHandle()) { throw new ArgumentNullException("method"); } if (!(type is RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); } Type baseType = type.BaseType; if (baseType == null || baseType != typeof(MulticastDelegate)) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); } Delegate @delegate = Delegate.InternalAlloc(type.TypeHandle.GetRuntimeType()); if ([email protected](target, method.GetMethodInfo(), RuntimeMethodHandle.GetDeclaringType(method.GetMethodInfo()), DelegateBindingFlags.RelaxedSignature)) { throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTargMeth")); } return @delegate; }
[System.Security.SecurityCritical] // auto-generated_required public static void PrepareMethod(RuntimeMethodHandle method) { unsafe { _PrepareMethod(method.GetMethodInfo(), null, 0); } }
[System.Security.SecurityCritical] // auto-generated_required public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation) { unsafe { int length; IntPtr[] instantiationHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(instantiation, out length); fixed (IntPtr* pInstantiation = instantiationHandles) { _PrepareMethod(method.GetMethodInfo(), pInstantiation, length); GC.KeepAlive(instantiation); } } }
public static unsafe void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation) { int num; fixed (IntPtr* ptrRef = RuntimeTypeHandle.CopyRuntimeTypeHandles(instantiation, out num)) { _PrepareMethod(method.GetMethodInfo(), ptrRef, num); GC.KeepAlive(instantiation); } }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType) { if (handle.IsNullHandle()) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage)) { FrameworkEventSource.Log.BeginGetMethodFromHandle(); } #endif MethodBase m = RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo()); #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null && m != null) { FrameworkEventSource.Log.EndGetMethodFromHandle(declaringType.GetRuntimeType().GetFullNameForEtw(), m.GetFullNameForEtw()); } #endif return m; }
[System.Security.SecuritySafeCritical] // auto-generated public int GetTokenFor(RuntimeMethodHandle method) { IRuntimeMethodInfo methodReal = method.GetMethodInfo(); RuntimeMethodHandleInternal rmhi = methodReal.Value; if (methodReal != null && !RuntimeMethodHandle.IsDynamicMethod(rmhi)) { RuntimeType type = RuntimeMethodHandle.GetDeclaringType(rmhi); if ((type != null) && RuntimeTypeHandle.HasInstantiation(type)) { // Do we really need to retrieve this much info just to throw an exception? MethodBase m = RuntimeType.GetMethodBase(methodReal); Type t = m.DeclaringType.GetGenericTypeDefinition(); throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGenericLcg"), m, t)); } } m_tokens.Add(method); return m_tokens.Count - 1 | (int)MetadataTokenType.MethodDef; }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType) { if (handle.IsNullHandle()) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); #if MONO MethodBase m = GetMethodFromHandleInternalType (handle.Value, declaringType.Value); if (m == null) throw new ArgumentException ("The handle is invalid."); return m; #else return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo()); #endif }
[System.Security.SecurityCritical] // auto-generated internal unsafe static Delegate CreateDelegateNoSecurityCheck(Type type, Object target, RuntimeMethodHandle method) { // Validate the parameters. if (type == null) throw new ArgumentNullException("type"); Contract.EndContractBlock(); if (method.IsNullHandle()) throw new ArgumentNullException("method"); RuntimeType rtType = type as RuntimeType; if (rtType == null) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); if (!rtType.IsDelegate()) throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),"type"); // Initialize the method... Delegate d = InternalAlloc(rtType); // This is a new internal API added in Whidbey. Currently it's only // used by the dynamic method code to generate a wrapper delegate. // Allow flexible binding options since the target method is // unambiguously provided to us. // < if (!d.BindToMethodInfo(target, method.GetMethodInfo(), RuntimeMethodHandle.GetDeclaringType(method.GetMethodInfo()), DelegateBindingFlags.RelaxedSignature | DelegateBindingFlags.SkipSecurityChecks)) throw new ArgumentException(Environment.GetResourceString("Arg_DlgtTargMeth")); return d; }
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) { if (handle.IsNullHandle()) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle")); } MethodBase methodBase = RuntimeType.GetMethodBase(handle.GetMethodInfo()); Type declaringType = methodBase.DeclaringType; if ((declaringType != null) && declaringType.IsGenericType) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGeneric"), new object[] { methodBase, declaringType.GetGenericTypeDefinition() })); } return methodBase; }