Browse Source

Fixed DefaultMemberReference for methods with parameters.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
70e62f42a1
  1. 20
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
  2. 12
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs
  3. 12
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMemberReference.cs

20
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

@ -21,6 +21,7 @@ using System.IO; @@ -21,6 +21,7 @@ using System.IO;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.TypeSystem.TestCase;
using ICSharpCode.NRefactory.Utils;
using NUnit.Framework;
@ -60,6 +61,25 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -60,6 +61,25 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
Assert.IsTrue(method.IsExplicitInterfaceImplementation);
Assert.AreEqual("System.IDisposable.Dispose", method.InterfaceImplementations.Single().FullName);
}
[Test]
public void ExplicitGenericInterfaceImplementation()
{
ITypeDefinition impl = GetTypeDefinition(typeof(NRefactory.TypeSystem.TestCase.ExplicitGenericInterfaceImplementation));
IType genericInterfaceOfString = compilation.FindType(typeof(IGenericInterface<string>));
IMethod implMethod1 = impl.Methods.Single(m => m.Name == "Test" && !m.Parameters[1].IsRef);
IMethod implMethod2 = impl.Methods.Single(m => m.Name == "Test" && m.Parameters[1].IsRef);
Assert.IsTrue(implMethod1.IsExplicitInterfaceImplementation);
Assert.IsTrue(implMethod2.IsExplicitInterfaceImplementation);
IMethod interfaceMethod1 = (IMethod)implMethod1.InterfaceImplementations.Single();
Assert.AreEqual(genericInterfaceOfString, interfaceMethod1.DeclaringType);
Assert.IsTrue(!interfaceMethod1.Parameters[1].IsRef);
IMethod interfaceMethod2 = (IMethod)implMethod2.InterfaceImplementations.Single();
Assert.AreEqual(genericInterfaceOfString, interfaceMethod2.DeclaringType);
Assert.IsTrue(interfaceMethod2.Parameters[1].IsRef);
}
}
[TestFixture]

12
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

@ -166,4 +166,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase @@ -166,4 +166,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase
{
void IDisposable.Dispose() {}
}
public interface IGenericInterface<T>
{
void Test<S>(T a, S b) where S : T;
void Test<S>(T a, ref S b);
}
public class ExplicitGenericInterfaceImplementation : IGenericInterface<string>
{
void IGenericInterface<string>.Test<T>(string a, T b) {}
void IGenericInterface<string>.Test<T>(string a, ref T b) {}
}
}

12
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMemberReference.cs

@ -70,7 +70,17 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -70,7 +70,17 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
if (parameterizedMember == null || parameterizedMember.Parameters.Count == 0)
return member;
} else if (parameterTypes.Count == parameterizedMember.Parameters.Count) {
bool signatureMatches = true;
for (int i = 0; i < parameterTypes.Count; i++) {
IType type1 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(resolvedParameterTypes[i]);
IType type2 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(parameterizedMember.Parameters[i].Type);
if (!type1.Equals(type2)) {
signatureMatches = false;
break;
}
}
if (signatureMatches)
return member;
}
}
return null;

Loading…
Cancel
Save