From 4d62192f6b43d126391fcb15f9749aaa541f9016 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Thu, 28 Jan 2021 15:17:14 +0100 Subject: [PATCH] include all generic parameters of the declaring type in the full name of generic parameters fixes Issue #46 Signed-off-by: Fritz Brandhuber --- ArchUnitNET/Loader/MonoCecilTypeExtensions.cs | 4 +- .../GithubIssuesTests/GithubIssue46Test.cs | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ArchUnitNETTests/GithubIssuesTests/GithubIssue46Test.cs diff --git a/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs b/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs index c6fa84320..34ccc632d 100644 --- a/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs +++ b/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs @@ -23,8 +23,8 @@ internal static string BuildFullName(this TypeReference typeReference) var genericParameter = (GenericParameter) typeReference; return (genericParameter.Type == GenericParameterType.Type - ? genericParameter.DeclaringType.FullName - : genericParameter.DeclaringMethod.FullName) + ? genericParameter.DeclaringType.BuildFullName() + : genericParameter.DeclaringMethod.BuildFullName()) + "+<" + genericParameter.Name + ">"; } diff --git a/ArchUnitNETTests/GithubIssuesTests/GithubIssue46Test.cs b/ArchUnitNETTests/GithubIssuesTests/GithubIssue46Test.cs new file mode 100644 index 000000000..8f1d671df --- /dev/null +++ b/ArchUnitNETTests/GithubIssuesTests/GithubIssue46Test.cs @@ -0,0 +1,50 @@ +// Copyright 2019 Florian Gather +// Copyright 2019 Fritz Brandhuber +// Copyright 2020 Pavel Fischer +// +// SPDX-License-Identifier: Apache-2.0 +// + +using System.Linq; +using ArchUnitNET.Domain; +using ArchUnitNET.Domain.Extensions; +using ArchUnitNET.Loader; +using Xunit; + +namespace ArchUnitNETTests.GithubIssuesTests +{ + public class GithubIssue46Test + { + private static readonly Architecture Architecture = + new ArchLoader().LoadAssembly(typeof(GithubIssue46Test).Assembly).Build(); + + private readonly MethodMember _oneGenericArgumentMethod; + private readonly MethodMember _twoGenericArgumentsMethod; + + public GithubIssue46Test() + { + var intf = Architecture.GetInterfaceOfType(typeof(ITestGenericMethods)); + _oneGenericArgumentMethod = intf.GetMethodMembers() + .First(member => member.GenericParameters.Count == 1); + _twoGenericArgumentsMethod = intf.GetMethodMembers() + .First(member => member.GenericParameters.Count == 2); + } + + + [Fact] + public void AssignDifferentGenericParametersToMethodsWithSameName() + { + Assert.NotNull(_oneGenericArgumentMethod); + Assert.NotNull(_twoGenericArgumentsMethod); + + Assert.Empty( + _oneGenericArgumentMethod.GenericParameters.Intersect(_twoGenericArgumentsMethod.GenericParameters)); + } + } + + internal interface ITestGenericMethods + { + void Method(); + void Method(); + } +} \ No newline at end of file