Browse Source

Fixed IMember.ToMemberReference() for explicit interface implementations.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
33b57d590d
  1. 1
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  2. 7
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedMember.cs
  3. 11
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs
  4. 11
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedProperty.cs
  5. 54
      ICSharpCode.NRefactory/TypeSystem/Implementation/ExplicitInterfaceImplementationMemberReference.cs

1
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -144,6 +144,7 @@ @@ -144,6 +144,7 @@
<Compile Include="TypeSystem\Implementation\DefaultUnresolvedTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\DefaultUnresolvedTypeParameter.cs" />
<Compile Include="TypeSystem\Implementation\DummyTypeParameter.cs" />
<Compile Include="TypeSystem\Implementation\ExplicitInterfaceImplementationMemberReference.cs" />
<Compile Include="TypeSystem\Implementation\FullNameAndTypeParameterCount.cs" />
<Compile Include="TypeSystem\Implementation\GetClassTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\GetMembersHelper.cs" />

7
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedMember.cs

@ -98,7 +98,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -98,7 +98,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public virtual IMemberReference ToMemberReference()
{
return new DefaultMemberReference(this.EntityType, this.DeclaringType.ToTypeReference(), this.Name);
var declTypeRef = this.DeclaringType.ToTypeReference();
if (IsExplicitInterfaceImplementation && InterfaceImplementations.Count == 1) {
return new ExplicitInterfaceImplementationMemberReference(declTypeRef, InterfaceImplementations[0].ToMemberReference());
} else {
return new DefaultMemberReference(this.EntityType, declTypeRef, this.Name);
}
}
internal IMethod GetAccessor(ref IMethod accessorField, IUnresolvedMethod unresolvedAccessor)

11
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs

@ -62,9 +62,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -62,9 +62,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public override IMemberReference ToMemberReference()
{
return new DefaultMemberReference(
this.EntityType, this.DeclaringType.ToTypeReference(), this.Name, this.TypeParameters.Count,
this.Parameters.Select(p => p.Type.ToTypeReference()).ToList());
var declTypeRef = this.DeclaringType.ToTypeReference();
if (IsExplicitInterfaceImplementation && InterfaceImplementations.Count == 1) {
return new ExplicitInterfaceImplementationMemberReference(declTypeRef, InterfaceImplementations[0].ToMemberReference());
} else {
return new DefaultMemberReference(
this.EntityType, declTypeRef, this.Name, this.TypeParameters.Count,
this.Parameters.Select(p => p.Type.ToTypeReference()).ToList());
}
}
}
}

11
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedProperty.cs

@ -63,9 +63,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -63,9 +63,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public override IMemberReference ToMemberReference()
{
return new DefaultMemberReference(
this.EntityType, this.DeclaringType.ToTypeReference(), this.Name, 0,
this.Parameters.Select(p => p.Type.ToTypeReference()).ToList());
var declTypeRef = this.DeclaringType.ToTypeReference();
if (IsExplicitInterfaceImplementation && InterfaceImplementations.Count == 1) {
return new ExplicitInterfaceImplementationMemberReference(declTypeRef, InterfaceImplementations[0].ToMemberReference());
} else {
return new DefaultMemberReference(
this.EntityType, declTypeRef, this.Name, 0,
this.Parameters.Select(p => p.Type.ToTypeReference()).ToList());
}
}
}
}

54
ICSharpCode.NRefactory/TypeSystem/Implementation/ExplicitInterfaceImplementationMemberReference.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// References a member that is an explicit interface implementation.
/// </summary>
public class ExplicitInterfaceImplementationMemberReference : IMemberReference
{
ITypeReference typeReference;
IMemberReference interfaceMemberReference;
public ExplicitInterfaceImplementationMemberReference(ITypeReference typeReference, IMemberReference interfaceMemberReference)
{
if (typeReference == null)
throw new ArgumentNullException("typeReference");
if (interfaceMemberReference == null)
throw new ArgumentNullException("interfaceMemberReference");
this.typeReference = typeReference;
this.interfaceMemberReference = interfaceMemberReference;
}
public IMember Resolve(ITypeResolveContext context)
{
IMember interfaceMember = interfaceMemberReference.Resolve(context);
if (interfaceMember == null)
return null;
IType type = typeReference.Resolve(context);
var members = type.GetMembers(
m => m.EntityType == interfaceMember.EntityType && m.IsExplicitInterfaceImplementation,
GetMemberOptions.IgnoreInheritedMembers);
return members.FirstOrDefault(m => m.InterfaceImplementations.Count == 1 && interfaceMember.Equals(m.InterfaceImplementations[0]));
}
}
}
Loading…
Cancel
Save