Skip to content

Commit

Permalink
Merge pull request #595 from ds5678/signature-comparer-symmetry
Browse files Browse the repository at this point in the history
SignatureComparer Symmetry
  • Loading branch information
Washi1337 authored Nov 25, 2024
2 parents 72eee24 + 4f7c06e commit 48a472f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public bool Equals(IMethodDescriptor? x, IMethodDescriptor? y)

if (x is MethodSpecification specification)
return Equals(specification, y as MethodSpecification);
else if (y is MethodSpecification)
return false;

return x.Name == y.Name
&& Equals(x.DeclaringType, y.DeclaringType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AsmResolver.DotNet.Signatures;
using AsmResolver.PE.DotNet.Metadata.Tables;

namespace AsmResolver.DotNet.Signatures
Expand Down Expand Up @@ -31,6 +30,8 @@ public bool Equals(TypeSignature? x, TypeSignature? y)
return true;
if (x is null || y is null)
return false;
if (x.ElementType != y.ElementType)
return false;

switch (x.ElementType)
{
Expand Down
14 changes: 14 additions & 0 deletions test/AsmResolver.DotNet.Tests/Signatures/SignatureComparerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using AsmResolver.DotNet.Signatures;
using AsmResolver.DotNet.TestCases.Methods;
using AsmResolver.PE.DotNet.Cil;
using AsmResolver.PE.DotNet.Metadata.Tables;
using Xunit;
Expand Down Expand Up @@ -117,6 +118,19 @@ public void MatchPropertySignature()
Assert.Equal(signature1, signature2, _comparer);
}

[Fact]
public void MethodSpecificationsAndTheirBaseMethodShouldNotMatch()
{
var moduleDefinition = ModuleDefinition.FromFile(typeof(GenericInstanceMethods).Assembly.Location, TestReaderParameters);
var methodDefinition = moduleDefinition
.GetAllTypes().First(t => t.Name == nameof(GenericInstanceMethods))
.Methods.First(t => t.Name == nameof(GenericInstanceMethods.InstanceMethodOneTypeParameter));
var methodSpecification = methodDefinition.MakeGenericInstanceMethod(moduleDefinition.CorLibTypeFactory.Int32);

Assert.NotEqual<IMethodDescriptor>(methodDefinition, methodSpecification, _comparer);
Assert.NotEqual<IMethodDescriptor>(methodSpecification, methodDefinition, _comparer);
}

[Fact]
public void NestedTypesWithSameNameButDifferentDeclaringTypeShouldNotMatch()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
namespace AsmResolver.DotNet.TestCases.Methods
namespace AsmResolver.DotNet.TestCases.Methods
{
public class GenericInstanceMethods
{
public void InstanceMethodOneTypeParameter<T>()
{
}
}
public class GenericInstanceMethods<T, U>
{
public void InstanceParameterlessMethod()
Expand Down

0 comments on commit 48a472f

Please sign in to comment.