protected virtual MethodInfo GetMethodImpl() { if (_methodBase == null) { RuntimeMethodHandle method = FindMethodHandle(); RuntimeTypeHandle declaringType = method.GetDeclaringType(); // need a proper declaring type instance method on a generic type if (declaringType.IsGenericTypeDefinition() || declaringType.HasInstantiation()) { bool isStatic = (method.GetAttributes() & MethodAttributes.Static) != (MethodAttributes)0; if (!isStatic) { if (_methodPtrAux == (IntPtr)0) { declaringType = _target.GetType().TypeHandle; // may throw NullRefException if the this is null but that's ok } else { // it's an open one, need to fetch the first arg of the instantiation MethodInfo invoke = this.GetType().GetMethod("Invoke"); declaringType = invoke.GetParameters()[0].ParameterType.TypeHandle; } } } _methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method); } return((MethodInfo)_methodBase); }
internal static MethodAttributes GetAttributes(IRuntimeMethodInfo method) { MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(method.Value); GC.KeepAlive(method); return(attributes); }
internal static MethodAttributes GetAttributes(IRuntimeMethodInfo method) { int num = (int)RuntimeMethodHandle.GetAttributes(method.Value); GC.KeepAlive((object)method); return((MethodAttributes)num); }
protected virtual MethodInfo GetMethodImpl() { if ((_methodBase == null) || !(_methodBase is MethodInfo)) { IRuntimeMethodInfo method = FindMethodHandle(); RuntimeType? declaringType = RuntimeMethodHandle.GetDeclaringType(method); // need a proper declaring type instance method on a generic type if (RuntimeTypeHandle.IsGenericTypeDefinition(declaringType) || RuntimeTypeHandle.HasInstantiation(declaringType)) { bool isStatic = (RuntimeMethodHandle.GetAttributes(method) & MethodAttributes.Static) != (MethodAttributes)0; if (!isStatic) { if (_methodPtrAux == IntPtr.Zero) { // The target may be of a derived type that doesn't have visibility onto the // target method. We don't want to call RuntimeType.GetMethodBase below with that // or reflection can end up generating a MethodInfo where the ReflectedType cannot // see the MethodInfo itself and that breaks an important invariant. But the // target type could include important generic type information we need in order // to work out what the exact instantiation of the method's declaring type is. So // we'll walk up the inheritance chain (which will yield exactly instantiated // types at each step) until we find the declaring type. Since the declaring type // we get from the method is probably shared and those in the hierarchy we're // walking won't be we compare using the generic type definition forms instead. Type?currentType = _target !.GetType(); Type targetType = declaringType.GetGenericTypeDefinition(); while (currentType != null) { if (currentType.IsGenericType && currentType.GetGenericTypeDefinition() == targetType) { declaringType = currentType as RuntimeType; break; } currentType = currentType.BaseType; } // RCWs don't need to be "strongly-typed" in which case we don't find a base type // that matches the declaring type of the method. This is fine because interop needs // to work with exact methods anyway so declaringType is never shared at this point. Debug.Assert(currentType != null || _target.GetType().IsCOMObject, "The class hierarchy should declare the method"); } else { // it's an open one, need to fetch the first arg of the instantiation MethodInfo invoke = this.GetType().GetMethod("Invoke") !; declaringType = (RuntimeType)invoke.GetParameters()[0].ParameterType; } } } _methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method) !; } return((MethodInfo)_methodBase); }
protected virtual MethodInfo GetMethodImpl() { if ((this._methodBase == null) || !(this._methodBase is MethodInfo)) { IRuntimeMethodInfo method = this.FindMethodHandle(); RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(method); if ((RuntimeTypeHandle.IsGenericTypeDefinition(declaringType) || RuntimeTypeHandle.HasInstantiation(declaringType)) && ((RuntimeMethodHandle.GetAttributes(method) & MethodAttributes.Static) == MethodAttributes.PrivateScope)) { if (!(this._methodPtrAux == IntPtr.Zero)) { declaringType = (RuntimeType)base.GetType().GetMethod("Invoke").GetParameters()[0].ParameterType; } else { Type type = this._target.GetType(); Type genericTypeDefinition = declaringType.GetGenericTypeDefinition(); while (true) { if (type.IsGenericType && (type.GetGenericTypeDefinition() == genericTypeDefinition)) { break; } type = type.BaseType; } declaringType = type as RuntimeType; } } this._methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method); } return((MethodInfo)this._methodBase); }
internal RuntimeConstructorInfo( RuntimeMethodHandle handle, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, BindingFlags bindingFlags) { ASSERT.POSTCONDITION(methodAttributes == handle.GetAttributes()); m_bindingFlags = bindingFlags; m_handle = handle; m_reflectedTypeCache = reflectedTypeCache; m_declaringType = declaringTypeHandle.GetRuntimeType(); m_parameters = null; // Created lazily when GetParameters() is called. m_toString = null; m_methodAttributes = methodAttributes; }