Пример #1
0
        /// <summary>
        /// Visits the generic type arguments of a generic type.
        /// </summary>
        /// <param name="genericType">The generic type whose type arguments to visit.</param>
        /// <returns>Result of visiting the generic type arguments; null if no types changed.</returns>
        protected TypeSlim[] VisitGenericTypeArguments(GenericTypeSlim genericType)
        {
            var res = default(TypeSlim[]);

            var n = genericType.GenericArgumentCount;

            for (int i = 0; i < n; i++)
            {
                var oldNode = genericType.GetGenericArgument(i);
                var newNode = Visit(oldNode);

                if (res != null)
                {
                    res[i] = newNode;
                }
                else
                {
                    if ((object)oldNode != newNode)
                    {
                        res = new TypeSlim[n];

                        for (int j = 0; j < i; j++)
                        {
                            res[j] = genericType.GetGenericArgument(j);
                        }

                        res[i] = newNode;
                    }
                }
            }

            return(res);
        }
Пример #2
0
        /// <summary>
        /// Visits a close generic type.
        /// </summary>
        /// <param name="type">Type to visit.</param>
        /// <returns>Result of the visit.</returns>
        protected virtual TypeSlim VisitGeneric(GenericTypeSlim type)
        {
            var typeDefinition = VisitAndConvert(type.GenericTypeDefinition);
            var arguments      = VisitGenericTypeArguments(type);

            // PERF: The == operator below will dispatch into the optimized Equals method for SimpeTypeBase,
            //       which avoids allocation of a TypeSlimEqualityComparator.

            if (typeDefinition == type.GenericTypeDefinition && arguments == null)
            {
                return(type);
            }
            else
            {
                return(type.Rewrite(typeDefinition, arguments));
            }
        }
Пример #3
0
 protected override string MakeGeneric(GenericTypeSlim type, string typeDefinition, ReadOnlyCollection <string> arguments)
 {
     return(string.Format(CultureInfo.InvariantCulture, "{0}<{1}>", typeDefinition, string.Join(", ", arguments)));
 }
Пример #4
0
 protected override string VisitGeneric(GenericTypeSlim type)
 {
     return(MakeGeneric(type, type.GenericTypeDefinition.Name, VisitGenericTypeArguments(type)));
 }