private static ImmutableArray <ITypeParameterSymbol> RenameTypeParameters(
            ImmutableArray <ITypeParameterSymbol> typeParameters,
            ImmutableArray <string> newNames,
            ITypeGenerator typeGenerator
            )
        {
            // We generate the type parameter in two passes.  The first creates the new type
            // parameter.  The second updates the constraints to point at this new type parameter.
            var newTypeParameters = new List <CodeGenerationTypeParameterSymbol>();

            var mapping = new Dictionary <ITypeSymbol, ITypeSymbol>(SymbolEqualityComparer.Default);

            for (var i = 0; i < typeParameters.Length; i++)
            {
                var typeParameter = typeParameters[i];

                var newTypeParameter = new CodeGenerationTypeParameterSymbol(
                    typeParameter.ContainingType,
                    typeParameter.GetAttributes(),
                    typeParameter.Variance,
                    newNames[i],
                    typeParameter.NullableAnnotation,
                    typeParameter.ConstraintTypes,
                    typeParameter.HasConstructorConstraint,
                    typeParameter.HasReferenceTypeConstraint,
                    typeParameter.HasValueTypeConstraint,
                    typeParameter.HasUnmanagedTypeConstraint,
                    typeParameter.HasNotNullConstraint,
                    typeParameter.Ordinal
                    );

                newTypeParameters.Add(newTypeParameter);
                mapping[typeParameter] = newTypeParameter;
            }

            // Now we update the constraints.
            foreach (var newTypeParameter in newTypeParameters)
            {
                newTypeParameter.ConstraintTypes = ImmutableArray.CreateRange(
                    newTypeParameter.ConstraintTypes,
                    t => t.SubstituteTypes(mapping, typeGenerator)
                    );
            }

            return(newTypeParameters.Cast <ITypeParameterSymbol>().ToImmutableArray());
        }
        private static ImmutableArray <ITypeParameterSymbol> RenameTypeParameters(
            ImmutableArray <ITypeParameterSymbol> typeParameters,
            IList <string> newNames,
            ITypeGenerator typeGenerator)
        {
            // We generate the type parameter in two passes.  The first creates the new type
            // parameter.  The second updates the constraints to point at this new type parameter.
            var newTypeParameters = new List <CodeGenerationTypeParameterSymbol>();

            // The use of AllNullabilityIgnoringSymbolComparer is tracked by https://github.com/dotnet/roslyn/issues/36093
            var mapping = new Dictionary <ITypeSymbol, ITypeSymbol>(AllNullabilityIgnoringSymbolComparer.Instance);

            for (var i = 0; i < typeParameters.Length; i++)
            {
                var typeParameter = typeParameters[i];

                var newTypeParameter = new CodeGenerationTypeParameterSymbol(
                    typeParameter.ContainingType,
                    typeParameter.GetAttributes(),
                    typeParameter.Variance,
                    newNames[i],
                    typeParameter.ConstraintTypes,
                    typeParameter.HasConstructorConstraint,
                    typeParameter.HasReferenceTypeConstraint,
                    typeParameter.HasValueTypeConstraint,
                    typeParameter.HasUnmanagedTypeConstraint,
                    typeParameter.HasNotNullConstraint,
                    typeParameter.Ordinal);

                newTypeParameters.Add(newTypeParameter);
                mapping[typeParameter] = newTypeParameter;
            }

            // Now we update the constraints.
            foreach (var newTypeParameter in newTypeParameters)
            {
                newTypeParameter.ConstraintTypes = ImmutableArray.CreateRange(newTypeParameter.ConstraintTypes, t => t.SubstituteTypes(mapping, typeGenerator));
            }

            return(newTypeParameters.Cast <ITypeParameterSymbol>().ToImmutableArray());
        }
Beispiel #3
0
        private static IList <ITypeParameterSymbol> RenameTypeParameters(
            IList <ITypeParameterSymbol> typeParameters,
            IList <string> newNames,
            ITypeGenerator typeGenerator)
        {
            // We generate the type parameter in two passes.  The first creates the new type
            // parameter.  The second updates the constraints to point at this new type parameter.
            var newTypeParameters = new List <CodeGenerationTypeParameterSymbol>();
            var mapping           = new Dictionary <ITypeSymbol, ITypeSymbol>();

            for (int i = 0; i < typeParameters.Count; i++)
            {
                var typeParameter = typeParameters[i];

                var newTypeParameter = new CodeGenerationTypeParameterSymbol(
                    typeParameter.ContainingType,
                    typeParameter.GetAttributes(),
                    typeParameter.Variance,
                    newNames[i],
                    typeParameter.ConstraintTypes,
                    typeParameter.HasConstructorConstraint,
                    typeParameter.HasReferenceTypeConstraint,
                    typeParameter.HasValueTypeConstraint,
                    typeParameter.Ordinal);

                newTypeParameters.Add(newTypeParameter);
                mapping.Add(typeParameter, newTypeParameter);
            }

            // Now we update the contraints.
            foreach (var newTypeParameter in newTypeParameters)
            {
                newTypeParameter.ConstraintTypes = newTypeParameter.ConstraintTypes.Select(
                    t => t.SubstituteTypes(mapping, typeGenerator)).AsImmutable();
            }

            return(newTypeParameters.Cast <ITypeParameterSymbol>().ToList());
        }
        private static IList<ITypeParameterSymbol> RenameTypeParameters(
            IList<ITypeParameterSymbol> typeParameters,
            IList<string> newNames,
            ITypeGenerator typeGenerator)
        {
            // We generate the type parameter in two passes.  The first creates the new type
            // parameter.  The second updates the constraints to point at this new type parameter.
            var newTypeParameters = new List<CodeGenerationTypeParameterSymbol>();
            var mapping = new Dictionary<ITypeSymbol, ITypeSymbol>();
            for (int i = 0; i < typeParameters.Count; i++)
            {
                var typeParameter = typeParameters[i];

                var newTypeParameter = new CodeGenerationTypeParameterSymbol(
                    typeParameter.ContainingType,
                    typeParameter.GetAttributes(),
                    typeParameter.Variance,
                    newNames[i],
                    typeParameter.ConstraintTypes,
                    typeParameter.HasConstructorConstraint,
                    typeParameter.HasReferenceTypeConstraint,
                    typeParameter.HasValueTypeConstraint,
                    typeParameter.Ordinal);

                newTypeParameters.Add(newTypeParameter);
                mapping[typeParameter] = newTypeParameter;
            }

            // Now we update the constraints.
            foreach (var newTypeParameter in newTypeParameters)
            {
                newTypeParameter.ConstraintTypes = ImmutableArray.CreateRange(newTypeParameter.ConstraintTypes, t => t.SubstituteTypes(mapping, typeGenerator));
            }

            return newTypeParameters.Cast<ITypeParameterSymbol>().ToList();
        }