IsGenericTypeDefinition() private method

private IsGenericTypeDefinition ( ) : bool
return bool
Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 protected override MethodInfo GetMethodImpl()
 {
     if (this._invocationCount != (IntPtr)0 && this._invocationList != null)
     {
         object[] objArray = this._invocationList as object[];
         if (objArray != null)
         {
             int index = (int)this._invocationCount - 1;
             return(((Delegate)objArray[index]).Method);
         }
         MulticastDelegate multicastDelegate = this._invocationList as MulticastDelegate;
         if (multicastDelegate != null)
         {
             return(multicastDelegate.GetMethodImpl());
         }
     }
     else if (this.IsUnmanagedFunctionPtr())
     {
         if (this._methodBase == null || !(this._methodBase is MethodInfo))
         {
             IRuntimeMethodInfo methodHandle = this.FindMethodHandle();
             RuntimeType        runtimeType  = RuntimeMethodHandle.GetDeclaringType(methodHandle);
             if (RuntimeTypeHandle.IsGenericTypeDefinition(runtimeType) || RuntimeTypeHandle.HasInstantiation(runtimeType))
             {
                 runtimeType = this.GetType() as RuntimeType;
             }
             this._methodBase = (object)(MethodInfo)RuntimeType.GetMethodBase(runtimeType, methodHandle);
         }
         return((MethodInfo)this._methodBase);
     }
     return(base.GetMethodImpl());
 }
Ejemplo n.º 4
0
        internal static RuntimeType GetGenericTypeDefinition(RuntimeType type)
        {
            RuntimeType o = type;

            if (RuntimeTypeHandle.HasInstantiation(o) && !RuntimeTypeHandle.IsGenericTypeDefinition(o))
            {
                RuntimeTypeHandle.GetGenericTypeDefinition(o.GetTypeHandleInternal(), JitHelpers.GetObjectHandleOnStack <RuntimeType>(ref o));
            }
            return(o);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        protected override MethodInfo GetMethodImpl()
        {
            if (_invocationCount != (IntPtr)0 && _invocationList != null)
            {
                // multicast case
                Object[] invocationList = _invocationList as Object[];
                if (invocationList != null)
                {
                    int index = (int)_invocationCount - 1;
                    return(((Delegate)invocationList[index]).Method);
                }
                MulticastDelegate innerDelegate = _invocationList as MulticastDelegate;
                if (innerDelegate != null)
                {
                    // must be a secure/wrapper delegate
                    return(innerDelegate.GetMethodImpl());
                }
            }
            else if (IsUnmanagedFunctionPtr())
            {
                // we handle unmanaged function pointers here because the generic ones (used for WinRT) would otherwise
                // be treated as open delegates by the base implementation, resulting in failure to get the MethodInfo
                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))
                    {
                        // we are returning the 'Invoke' method of this delegate so use this.GetType() for the exact type
                        RuntimeType reflectedType = GetType() as RuntimeType;
                        declaringType = reflectedType;
                    }
                    _methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method);
                }
                return((MethodInfo)_methodBase);
            }

            // Otherwise, must be an inner delegate of a SecureDelegate of an open virtual method. In that case, call base implementation
            return(base.GetMethodImpl());
        }
Ejemplo n.º 7
0
        internal static __ComGenericInterfaceDispatcher CreateGenericComDispatcher(RuntimeTypeHandle genericDispatcherDef, RuntimeTypeHandle[] genericArguments, __ComObject comThisPointer)
        {
#if !RHTESTCL && !CORECLR && !CORERT
            Debug.Assert(genericDispatcherDef.IsGenericTypeDefinition());
            Debug.Assert(genericArguments != null && genericArguments.Length > 0);

            RuntimeTypeHandle instantiatedDispatcherType;
            if (!Internal.Runtime.TypeLoader.TypeLoaderEnvironment.Instance.TryGetConstructedGenericTypeForComponents(genericDispatcherDef, genericArguments, out instantiatedDispatcherType))
                return null;    // ERROR

            __ComGenericInterfaceDispatcher dispatcher = (__ComGenericInterfaceDispatcher)InteropExtensions.RuntimeNewObject(instantiatedDispatcherType);
            dispatcher.m_comObject = comThisPointer;

            return dispatcher;
#else
            return null;
#endif
        }