IsGenericType() public static method

public static IsGenericType ( System.TypeSpec type ) : bool
type System.TypeSpec
return bool
Ejemplo n.º 1
0
Archivo: doc.cs Proyecto: mdae/MonoRT
        static string GetSignatureForDoc(Type type)
        {
#if GMCS_SOURCE
            if (TypeManager.IsGenericParameter(type))
            {
                return((type.DeclaringMethod != null ? "``" : "`") + TypeManager.GenericParameterPosition(type));
            }

            if (TypeManager.IsGenericType(type))
            {
                string g = type.Namespace;
                if (g != null && g.Length > 0)
                {
                    g += '.';
                }
                int idx = type.Name.LastIndexOf('`');
                g += (idx < 0 ? type.Name : type.Name.Substring(0, idx)) + '{';
                int argpos = 0;
                foreach (Type t in type.GetGenericArguments())
                {
                    g += (argpos++ > 0 ? "," : String.Empty) + GetSignatureForDoc(t);
                }
                g += '}';
                return(g);
            }
#endif

            string name = type.FullName != null ? type.FullName : type.Name;
            return(name.Replace("+", ".").Replace('&', '@'));
        }
Ejemplo n.º 2
0
        static string GetSignatureForDoc(TypeSpec type)
        {
            var tp = type as TypeParameterSpec;

            if (tp != null)
            {
                int c = 0;
                type = type.DeclaringType;
                while (type != null && type.DeclaringType != null)
                {
                    type = type.DeclaringType;
                    c   += type.MemberDefinition.TypeParametersCount;
                }
                var prefix = tp.IsMethodOwned ? "``" : "`";
                return(prefix + (c + tp.DeclaredPosition));
            }

            var pp = type as PointerContainer;

            if (pp != null)
            {
                return(GetSignatureForDoc(pp.Element) + "*");
            }

            ArrayContainer ap = type as ArrayContainer;

            if (ap != null)
            {
                return(GetSignatureForDoc(ap.Element) +
                       ArrayContainer.GetPostfixSignature(ap.Rank));
            }

            if (TypeManager.IsGenericType(type))
            {
                string g = type.MemberDefinition.Namespace;
                if (g != null && g.Length > 0)
                {
                    g += '.';
                }
                int idx = type.Name.LastIndexOf('`');
                g += (idx < 0 ? type.Name : type.Name.Substring(0, idx)) + '{';
                int argpos = 0;
                foreach (TypeSpec t in TypeManager.GetTypeArguments(type))
                {
                    g += (argpos++ > 0 ? "," : String.Empty) + GetSignatureForDoc(t);
                }
                g += '}';
                return(g);
            }

            string name = type.GetMetaInfo().FullName != null?type.GetMetaInfo().FullName : type.Name;

            return(name.Replace("+", ".").Replace('&', '@'));
        }
Ejemplo n.º 3
0
        //
        // Returns the MethodBase for "Invoke" from a delegate type, this is used
        // to extract the signature of a delegate.
        //
        public static MethodInfo GetInvokeMethod(CompilerContext ctx, Type container_type, Type delegate_type)
        {
            Type dt = delegate_type;

            Type[] g_args = null;
            if (TypeManager.IsGenericType(delegate_type))
            {
                g_args        = TypeManager.GetTypeArguments(delegate_type);
                delegate_type = TypeManager.DropGenericTypeArguments(delegate_type);
            }

            Delegate   d = TypeManager.LookupDelegate(delegate_type);
            MethodInfo invoke;

            if (d != null)
            {
#if GMCS_SOURCE
                if (g_args != null)
                {
                    invoke = TypeBuilder.GetMethod(dt, d.InvokeBuilder);
#if MS_COMPATIBLE
                    ParametersCompiled p = (ParametersCompiled)d.Parameters.InflateTypes(g_args, g_args);
                    TypeManager.RegisterMethod(invoke, p);
#endif
                    return(invoke);
                }
#endif
                return(d.InvokeBuilder);
            }

            Expression ml = Expression.MemberLookup(ctx, container_type, null, dt,
                                                    "Invoke", Location.Null);

            MethodGroupExpr mg = ml as MethodGroupExpr;
            if (mg == null)
            {
                ctx.Report.Error(-100, Location.Null, "Internal error: could not find Invoke method!");
                // FIXME: null will cause a crash later
                return(null);
            }

            invoke = (MethodInfo)mg.Methods[0];
#if MS_COMPATIBLE
            if (g_args != null)
            {
                AParametersCollection p = TypeManager.GetParameterData(invoke);
                p = p.InflateTypes(g_args, g_args);
                TypeManager.RegisterMethod(invoke, p);
                return(invoke);
            }
#endif

            return(invoke);
        }
Ejemplo n.º 4
0
        static bool CheckType(Type ret, out Type original_iterator_type, out bool is_enumerable)
        {
            original_iterator_type = null;
            is_enumerable          = false;

            if (ret == TypeManager.ienumerable_type)
            {
                original_iterator_type = TypeManager.object_type;
                is_enumerable          = true;
                return(true);
            }
            if (ret == TypeManager.ienumerator_type)
            {
                original_iterator_type = TypeManager.object_type;
                is_enumerable          = false;
                return(true);
            }

            if (!TypeManager.IsGenericType(ret))
            {
                return(false);
            }

            Type[] args = TypeManager.GetTypeArguments(ret);
            if (args.Length != 1)
            {
                return(false);
            }

            Type gt = TypeManager.DropGenericTypeArguments(ret);

            if (gt == TypeManager.generic_ienumerable_type)
            {
                original_iterator_type = args [0];
                is_enumerable          = true;
                return(true);
            }

            if (gt == TypeManager.generic_ienumerator_type)
            {
                original_iterator_type = args [0];
                is_enumerable          = false;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public static ConstructorInfo GetConstructor(CompilerContext ctx, Type container_type, Type delegate_type)
        {
            Type dt = delegate_type;

            Type[] g_args = null;
            if (TypeManager.IsGenericType(delegate_type))
            {
                g_args        = TypeManager.GetTypeArguments(delegate_type);
                delegate_type = TypeManager.DropGenericTypeArguments(delegate_type);
            }

            Delegate d = TypeManager.LookupDelegate(delegate_type);

            if (d != null)
            {
#if GMCS_SOURCE
                if (g_args != null)
                {
                    return(TypeBuilder.GetConstructor(dt, d.ConstructorBuilder));
                }
#endif
                return(d.ConstructorBuilder);
            }

            Expression ml = Expression.MemberLookup(ctx, container_type,
                                                    null, dt, ConstructorInfo.ConstructorName, MemberTypes.Constructor,
                                                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, Location.Null);

            MethodGroupExpr mg = ml as MethodGroupExpr;
            if (mg == null)
            {
                ctx.Report.Error(-100, Location.Null, "Internal error: could not find delegate constructor!");
                // FIXME: null will cause a crash later
                return(null);
            }

            return((ConstructorInfo)mg.Methods[0]);
        }
Ejemplo n.º 6
0
            /// <summary>
            ///   Check whether `a' and `b' may become equal generic types.
            ///   The algorithm to do that is a little bit complicated.
            /// </summary>
            static bool MayBecomeEqualGenericTypes(TypeSpec a, TypeSpec b)
            {
                if (a.IsGenericParameter)
                {
                    //
                    // If a is an array of a's type, they may never
                    // become equal.
                    //
                    if (b.IsArray)
                    {
                        return(false);
                    }

                    //
                    // If b is a generic parameter or an actual type,
                    // they may become equal:
                    //
                    //    class X<T,U> : I<T>, I<U>
                    //    class X<T> : I<T>, I<float>
                    //
                    if (b.IsGenericParameter)
                    {
                        return(a.DeclaringType == b.DeclaringType);
                    }

                    //
                    // We're now comparing a type parameter with a
                    // generic instance.  They may become equal unless
                    // the type parameter appears anywhere in the
                    // generic instance:
                    //
                    //    class X<T,U> : I<T>, I<X<U>>
                    //        -> error because you could instanciate it as
                    //           X<X<int>,int>
                    //
                    //    class X<T> : I<T>, I<X<T>> -> ok
                    //

                    return(!ContainsTypeParameter(a, b));
                }

                if (b.IsGenericParameter)
                {
                    return(MayBecomeEqualGenericTypes(b, a));
                }

                //
                // At this point, neither a nor b are a type parameter.
                //
                // If one of them is a generic instance, compare them (if the
                // other one is not a generic instance, they can never
                // become equal).
                //
                if (TypeManager.IsGenericType(a) || TypeManager.IsGenericType(b))
                {
                    return(IsEqual(a, b));
                }

                //
                // If both of them are arrays.
                //
                var a_ac = a as ArrayContainer;

                if (a_ac != null)
                {
                    var b_ac = b as ArrayContainer;
                    if (b_ac == null || a_ac.Rank != b_ac.Rank)
                    {
                        return(false);
                    }

                    return(MayBecomeEqualGenericTypes(a_ac.Element, b_ac.Element));
                }

                //
                // Ok, two ordinary types.
                //
                return(false);
            }