diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
index 999a6cf79d..7e90fd8ad4 100644
--- a/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
+++ b/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
@@ -77,7 +77,7 @@ namespace OtherNS {
{
return new TypeSystemAstBuilder(
new CSharpResolver(ctx) {
- UsingScope = currentTypeDef != null ? parsedFile.GetUsingScope(currentTypeDef.Region.Begin) : parsedFile.RootUsingScope,
+ CurrentUsingScope = currentTypeDef != null ? parsedFile.GetUsingScope(currentTypeDef.Region.Begin) : parsedFile.RootUsingScope,
CurrentTypeDefinition = currentTypeDef
});
}
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
index 74f85bc954..5ba68ef874 100644
--- a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
+++ b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
@@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public void SimpleNameLookupWithoutContext()
{
// nothing should be found without specifying any UsingScope - however, the resolver also must not crash
- resolver.UsingScope = null;
+ resolver.CurrentUsingScope = null;
Assert.IsTrue(resolver.ResolveSimpleName("System", new IType[0]).IsError);
}
@@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void NamespaceInParentNamespaceLookup()
{
- resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
+ resolver.CurrentUsingScope = MakeUsingScope("System.Collections.Generic");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
@@ -102,7 +102,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public void AliasToImportedType2()
{
AddUsing("System");
- resolver.UsingScope = new UsingScope(resolver.UsingScope, "SomeNamespace");
+ resolver.CurrentUsingScope = new UsingScope(resolver.CurrentUsingScope, "SomeNamespace");
AddUsingAlias("x", "String");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("x", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
@@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void FindClassInCurrentNamespace()
{
- resolver.UsingScope = MakeUsingScope("System.Collections");
+ resolver.CurrentUsingScope = MakeUsingScope("System.Collections");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("String", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
}
@@ -140,7 +140,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void FindNeighborNamespace()
{
- resolver.UsingScope = MakeUsingScope("System.Collections");
+ resolver.CurrentUsingScope = MakeUsingScope("System.Collections");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
@@ -148,7 +148,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[Test]
public void FindTypeParameters()
{
- resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
+ resolver.CurrentUsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentTypeDefinition = context.GetTypeDefinition(typeof(List<>));
resolver.CurrentMember = resolver.CurrentTypeDefinition.Methods.Single(m => m.Name == "ConvertAll");
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
index efd832af36..a264c0aa46 100644
--- a/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
+++ b/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
@@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
project = new SimpleProjectContent();
context = new CompositeTypeResolveContext(new [] { project, mscorlib, CecilLoaderTests.SystemCore });
resolver = new CSharpResolver(context);
- resolver.UsingScope = MakeUsingScope("");
+ resolver.CurrentUsingScope = MakeUsingScope("");
}
protected UsingScope MakeUsingScope(string namespaceName)
@@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
///
protected void AddUsing(string namespaceName)
{
- resolver.UsingScope.Usings.Add(MakeReference(namespaceName));
+ resolver.CurrentUsingScope.Usings.Add(MakeReference(namespaceName));
}
///
@@ -71,15 +71,15 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
///
protected void AddUsingAlias(string alias, string target)
{
- resolver.UsingScope.UsingAliases.Add(new KeyValuePair(alias, MakeReference(target)));
+ resolver.CurrentUsingScope.UsingAliases.Add(new KeyValuePair(alias, MakeReference(target)));
}
protected ITypeOrNamespaceReference MakeReference(string namespaceName)
{
string[] nameParts = namespaceName.Split('.');
- ITypeOrNamespaceReference r = new SimpleTypeOrNamespaceReference(nameParts[0], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope, SimpleNameLookupMode.TypeInUsingDeclaration);
+ ITypeOrNamespaceReference r = new SimpleTypeOrNamespaceReference(nameParts[0], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.CurrentUsingScope, SimpleNameLookupMode.TypeInUsingDeclaration);
for (int i = 1; i < nameParts.Length; i++) {
- r = new MemberTypeOrNamespaceReference(r, nameParts[i], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope);
+ r = new MemberTypeOrNamespaceReference(r, nameParts[i], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.CurrentUsingScope);
}
return r;
}
@@ -194,8 +194,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
SetUp();
- ParsedFile parsedFile = new ParsedFile("test.cs", resolver.UsingScope);
- TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.UsingScope, null);
+ ParsedFile parsedFile = new ParsedFile("test.cs", resolver.CurrentUsingScope);
+ TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.CurrentUsingScope, null);
cu.AcceptVisitor(convertVisitor, null);
project.UpdateProjectContent(null, convertVisitor.ParsedFile);
diff --git a/ICSharpCode.NRefactory/Documentation/IDStringProvider.cs b/ICSharpCode.NRefactory/Documentation/IDStringProvider.cs
index 0c28f2a127..0131125c58 100644
--- a/ICSharpCode.NRefactory/Documentation/IDStringProvider.cs
+++ b/ICSharpCode.NRefactory/Documentation/IDStringProvider.cs
@@ -170,6 +170,15 @@ namespace ICSharpCode.NRefactory.Documentation
AppendTypeName(b, resolvedType);
return;
}
+ KnownTypeReference knownType = type as KnownTypeReference;
+ if (knownType != null) {
+ if (!string.IsNullOrEmpty(knownType.Namespace)) {
+ b.Append(knownType.Namespace);
+ b.Append('.');
+ }
+ b.Append(knownType.Name);
+ return;
+ }
GetClassTypeReference gctr = type as GetClassTypeReference;
if (gctr != null) {
if (!string.IsNullOrEmpty(gctr.Namespace)) {
@@ -240,15 +249,6 @@ namespace ICSharpCode.NRefactory.Documentation
static int AppendParameterizedTypeName(StringBuilder b, ITypeReference type, IList typeArguments, ITypeResolveContext context)
{
- KnownTypeReference knownType = type as KnownTypeReference;
- if (knownType != null) {
- if (!string.IsNullOrEmpty(knownType.Namespace)) {
- b.Append(knownType.Namespace);
- b.Append('.');
- }
- b.Append(knownType.Name);
- return 0;
- }
GetClassTypeReference gctr = type as GetClassTypeReference;
if (gctr != null) {
if (!string.IsNullOrEmpty(gctr.Namespace)) {
diff --git a/ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs b/ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs
index 3e12f549e8..e8eb17f436 100644
--- a/ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs
@@ -86,7 +86,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
[Serializable]
- public class ByReferenceTypeReference : ITypeReference, ISupportsInterning
+ public sealed class ByReferenceTypeReference : ITypeReference, ISupportsInterning
{
ITypeReference elementType;
diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
index 656e1348ce..29a1c4f893 100644
--- a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
@@ -138,24 +138,27 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
return this;
}
- public override int GetHashCode()
- {
- unchecked {
- return (int)ownerType * 178256151 + index;
- }
- }
-
- public override bool Equals(object obj)
- {
- return Equals(obj as IType);
- }
+// public override int GetHashCode()
+// {
+// unchecked {
+// return (int)ownerType * 178256151 + index;
+// }
+// }
+//
+// public override bool Equals(object obj)
+// {
+// return Equals(obj as IType);
+// }
public bool Equals(IType other)
{
- DefaultTypeParameter p = other as DefaultTypeParameter;
- if (p == null)
- return false;
- return ownerType == p.ownerType && index == p.index;
+ // Use reference equality for type parameters. While we could consider any types with same
+ // ownerType + index as equal for the type system, doing so makes it difficult to cache calculation
+ // results based on types - e.g. the cache in the Conversions class.
+ return this == other;
+ // We can still consider type parameters of different methods/classes to be equal to each other,
+ // if they have been interned. But then also all constraints are equal, so caching conversions
+ // is valid in that case.
}
public EntityType OwnerType {
diff --git a/ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs b/ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs
index b2ad99027a..6cacdfc2aa 100644
--- a/ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs
@@ -31,82 +31,82 @@ namespace ICSharpCode.NRefactory.TypeSystem
///
/// Gets a type reference pointing to the void type.
///
- public static readonly KnownTypeReference Void = new KnownTypeReference(TypeCode.Empty);
+ public static readonly ITypeReference Void = new KnownTypeReference(TypeCode.Empty);
///
/// Gets a type reference pointing to the object type.
///
- public static readonly KnownTypeReference Object = new KnownTypeReference(TypeCode.Object);
+ public static readonly ITypeReference Object = new KnownTypeReference(TypeCode.Object);
///
/// Gets a type reference pointing to the bool type.
///
- public static readonly KnownTypeReference Boolean = new KnownTypeReference(TypeCode.Boolean);
+ public static readonly ITypeReference Boolean = new KnownTypeReference(TypeCode.Boolean);
///
/// Gets a type reference pointing to the char type.
///
- public static readonly KnownTypeReference Char = new KnownTypeReference(TypeCode.Char);
+ public static readonly ITypeReference Char = new KnownTypeReference(TypeCode.Char);
///
/// Gets a type reference pointing to the sbyte type.
///
- public static readonly KnownTypeReference SByte = new KnownTypeReference(TypeCode.SByte);
+ public static readonly ITypeReference SByte = new KnownTypeReference(TypeCode.SByte);
///
/// Gets a type reference pointing to the byte type.
///
- public static readonly KnownTypeReference Byte = new KnownTypeReference(TypeCode.Byte);
+ public static readonly ITypeReference Byte = new KnownTypeReference(TypeCode.Byte);
///
/// Gets a type reference pointing to the short type.
///
- public static readonly KnownTypeReference Int16 = new KnownTypeReference(TypeCode.Int16);
+ public static readonly ITypeReference Int16 = new KnownTypeReference(TypeCode.Int16);
///
/// Gets a type reference pointing to the ushort type.
///
- public static readonly KnownTypeReference UInt16 = new KnownTypeReference(TypeCode.UInt16);
+ public static readonly ITypeReference UInt16 = new KnownTypeReference(TypeCode.UInt16);
///
/// Gets a type reference pointing to the int type.
///
- public static readonly KnownTypeReference Int32 = new KnownTypeReference(TypeCode.Int32);
+ public static readonly ITypeReference Int32 = new KnownTypeReference(TypeCode.Int32);
///
/// Gets a type reference pointing to the uint type.
///
- public static readonly KnownTypeReference UInt32 = new KnownTypeReference(TypeCode.UInt32);
+ public static readonly ITypeReference UInt32 = new KnownTypeReference(TypeCode.UInt32);
///
/// Gets a type reference pointing to the long type.
///
- public static readonly KnownTypeReference Int64 = new KnownTypeReference(TypeCode.Int64);
+ public static readonly ITypeReference Int64 = new KnownTypeReference(TypeCode.Int64);
///
/// Gets a type reference pointing to the ulong type.
///
- public static readonly KnownTypeReference UInt64 = new KnownTypeReference(TypeCode.UInt64);
+ public static readonly ITypeReference UInt64 = new KnownTypeReference(TypeCode.UInt64);
///
/// Gets a type reference pointing to the float type.
///
- public static readonly KnownTypeReference Single = new KnownTypeReference(TypeCode.Single);
+ public static readonly ITypeReference Single = new KnownTypeReference(TypeCode.Single);
///
/// Gets a type reference pointing to the double type.
///
- public static readonly KnownTypeReference Double = new KnownTypeReference(TypeCode.Double);
+ public static readonly ITypeReference Double = new KnownTypeReference(TypeCode.Double);
///
/// Gets a type reference pointing to the decimal type.
///
- public static readonly KnownTypeReference Decimal = new KnownTypeReference(TypeCode.Decimal);
+ public static readonly ITypeReference Decimal = new KnownTypeReference(TypeCode.Decimal);
///
/// Gets a type reference pointing to the string type.
///
- public static readonly KnownTypeReference String = new KnownTypeReference(TypeCode.String);
+ public static readonly ITypeReference String = new KnownTypeReference(TypeCode.String);
///
/// Gets a type reference pointing to the System.Type type.
diff --git a/ICSharpCode.NRefactory/TypeSystem/PointerType.cs b/ICSharpCode.NRefactory/TypeSystem/PointerType.cs
index ad96faa155..7660dadd83 100644
--- a/ICSharpCode.NRefactory/TypeSystem/PointerType.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/PointerType.cs
@@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
[Serializable]
- public class PointerTypeReference : ITypeReference, ISupportsInterning
+ public sealed class PointerTypeReference : ITypeReference, ISupportsInterning
{
ITypeReference elementType;