diff --git a/ICSharpCode.NRefactory/TypeSystem/IMethod.cs b/ICSharpCode.NRefactory/TypeSystem/IMethod.cs index c534c0d815..ddf5c97513 100644 --- a/ICSharpCode.NRefactory/TypeSystem/IMethod.cs +++ b/ICSharpCode.NRefactory/TypeSystem/IMethod.cs @@ -88,20 +88,27 @@ namespace ICSharpCode.NRefactory.TypeSystem /// Gets the unresolved method parts. /// For partial methods, this returns all parts. /// Otherwise, this returns an array with a single element (new[] { UnresolvedMember }). + /// NOTE: The type will change to IReadOnlyList in future versions. /// IList Parts { get; } /// /// Gets the attributes associated with the return type. (e.g. [return: MarshalAs(...)]) + /// NOTE: The type will change to IReadOnlyList in future versions. /// IList ReturnTypeAttributes { get; } - + + + /// + /// NOTE: The type will change to IReadOnlyList in future versions. + /// IList TypeParameters { get; } /// /// Gets the type arguments passed to this method. /// If only the type parameters for the class were specified and the generic method /// itself is not specialized yet, this property will return an empty list. + /// NOTE: The type will change to IReadOnlyList in future versions. /// IList TypeArguments { get; diff --git a/ICSharpCode.NRefactory/TypeSystem/IType.cs b/ICSharpCode.NRefactory/TypeSystem/IType.cs index 2d010e22b9..d611d0c065 100644 --- a/ICSharpCode.NRefactory/TypeSystem/IType.cs +++ b/ICSharpCode.NRefactory/TypeSystem/IType.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using ICSharpCode.NRefactory.TypeSystem.Implementation; namespace ICSharpCode.NRefactory.TypeSystem { @@ -80,7 +81,15 @@ namespace ICSharpCode.NRefactory.TypeSystem /// Gets the number of type parameters. /// int TypeParameterCount { get; } - + + /// + /// Gets the type arguments passed to this type. + /// If only the type parameters for the class were specified and the generic type + /// itself is not specialized yet or the TypeParameterCount is 0, this property will return an empty list. + /// NOTE: The type will change to IReadOnlyList in future versions. + /// + IList TypeArguments { get; } + /// /// Calls ITypeVisitor.Visit for this type. /// @@ -110,6 +119,22 @@ namespace ICSharpCode.NRefactory.TypeSystem /// Otherwise, the main resolve context of a compilation is sufficient. /// ITypeReference ToTypeReference(); + + /// + /// Gets a type visitor that performs the substitution of class type parameters with the type arguments + /// of this parameterized type. + /// Returns TypeParameterSubstitution.Identity if the type is not parametrized. + /// + TypeParameterSubstitution GetSubstitution(); + + /// + /// Gets a type visitor that performs the substitution of class type parameters with the type arguments + /// of this parameterized type, + /// and also substitutes method type parameters with the specified method type arguments. + /// Returns TypeParameterSubstitution.Identity if the type is not parametrized. + /// + TypeParameterSubstitution GetSubstitution(IList methodTypeArguments); + /// /// Gets inner classes (including inherited inner classes). diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs index cede6c7a8b..6afa854d0c 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedTypeParameter.cs @@ -206,7 +206,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation int IType.TypeParameterCount { get { return 0; } } - + + readonly static IList emptyTypeArguments = new IType[0]; + IList IType.TypeArguments { + get { return emptyTypeArguments; } + } + public abstract IEnumerable DirectBaseTypes { get; } public string Name { @@ -326,7 +331,17 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation else return GetMembersHelper.GetAccessors(this, FilterNonStatic(filter), options); } + + public TypeParameterSubstitution GetSubstitution() + { + return TypeParameterSubstitution.Identity; + } + public TypeParameterSubstitution GetSubstitution(IList methodTypeArguments) + { + return TypeParameterSubstitution.Identity; + } + static Predicate FilterNonStatic(Predicate filter) where T : class, IUnresolvedMember { if (filter == null) diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs index 48aac56559..3d68ee62d0 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs @@ -58,7 +58,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation public virtual int TypeParameterCount { get { return 0; } } - + + readonly static IList emptyTypeArguments = new IType[0]; + IList IType.TypeArguments { + get { return emptyTypeArguments; } + } + public virtual IType DeclaringType { get { return null; } } @@ -128,6 +133,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation return EmptyList.Instance; } + public TypeParameterSubstitution GetSubstitution() + { + return TypeParameterSubstitution.Identity; + } + + public TypeParameterSubstitution GetSubstitution(IList methodTypeArguments) + { + return TypeParameterSubstitution.Identity; + } + public override sealed bool Equals(object obj) { return Equals(obj as IType); diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs index b6cd1e09ce..cee886cb57 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs @@ -492,7 +492,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation public int TypeParameterCount { get { return parts[0].TypeParameters.Count; } } - + + readonly static IList emptyTypeArguments = new IType[0]; + IList IType.TypeArguments { + get { return emptyTypeArguments; } + } + #region DirectBaseTypes IList directBaseTypes; @@ -904,6 +909,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation } #endregion + public TypeParameterSubstitution GetSubstitution() + { + return TypeParameterSubstitution.Identity; + } + + public TypeParameterSubstitution GetSubstitution(IList methodTypeArguments) + { + return TypeParameterSubstitution.Identity; + } + public bool Equals(IType other) { return this == other; diff --git a/ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs b/ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs index dbe0b86f15..658f715e0c 100644 --- a/ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs +++ b/ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs @@ -137,12 +137,12 @@ namespace ICSharpCode.NRefactory.TypeSystem return ReflectionName; } - public ReadOnlyCollection TypeArguments { + public IList TypeArguments { get { - return Array.AsReadOnly(typeArguments); + return typeArguments; } } - + /// /// Same as 'parameterizedType.TypeArguments[index]', but is a bit more efficient (doesn't require the read-only wrapper). ///