/// <summary>
        /// Returns a constructed type given its instance type and type arguments.
        /// </summary>
        /// <param name="instanceType">the instance type to construct the result from</param>
        /// <param name="typeArguments">the immediate type arguments to be replaced for type parameters in the instance type</param>
        /// <returns></returns>
        internal static NamedTypeSymbol Construct1(this NamedTypeSymbol instanceType, ReadOnlyArray <TypeSymbol> typeArguments)
        {
            Debug.Assert(instanceType.ConstructedFrom == instanceType);

            var sequenceEqual = true;
            var args          = instanceType.TypeArguments;

            if (args.Count != typeArguments.Count)
            {
                sequenceEqual = false;
            }
            else
            {
                for (int i = 0; i < args.Count; i++)
                {
                    if (args[i] != typeArguments[i])
                    {
                        sequenceEqual = false;
                        break;
                    }
                }
            }

            return(sequenceEqual
                ? instanceType
                : ConstructedNamedTypeSymbol.Make(instanceType, typeArguments));
        }
Exemple #2
0
        /// <summary>
        /// </summary>
        /// <param name="namedTypeSymbol">
        /// </param>
        /// <param name="map">
        /// </param>
        /// <returns>
        /// </returns>
        private static ConstructedNamedTypeSymbol ConstructGenericTypeSymbol(NamedTypeSymbol namedTypeSymbol, IDictionary <IType, IType> map)
        {
            var mapFilteredByTypeParameters = namedTypeSymbol.TypeArguments != null
                                                  ? SelectGenericsFromArguments(namedTypeSymbol, map)
                                                  : SelectGenericsFromParameters(namedTypeSymbol, map);

            if (mapFilteredByTypeParameters == null)
            {
                return(null);
            }

            var newType = new ConstructedNamedTypeSymbol(namedTypeSymbol.ConstructedFrom, ImmutableArray.Create(mapFilteredByTypeParameters));

            return(newType);
        }