Skip to content

Commit 25676e9

Browse files
authored
fix(commons): reduce fullNames for generic method definitions (#572)
If a method is a constructed generic method (like Class.Method<int>()), its fullName is now calculated based on its generic definition. That makes fullNames independent of type arguments (i.e., on concrete types).
1 parent 9345054 commit 25676e9

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Allure.Net.Commons.Tests/FunctionTests/IdTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void TestFullNameFromMethodOfNestedGenericClass()
157157
public void TestFullNameFromConstructedGenericMethodOfNestedConstructedGenericClass()
158158
{
159159
var method = typeof(MyClass<MyClass>).GetMethod(
160-
nameof(MyClass<int>.GenericMethodOfGenericClass),
160+
nameof(MyClass<MyClass>.GenericMethodOfGenericClass),
161161
BindingFlags.Instance | BindingFlags.NonPublic
162162
).MakeGenericMethod(typeof(MyClass));
163163

@@ -166,11 +166,9 @@ public void TestFullNameFromConstructedGenericMethodOfNestedConstructedGenericCl
166166
Assert.That(actualFullName, Is.EqualTo(
167167
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[" +
168168
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]" +
169-
".GenericMethodOfGenericClass[" +
170-
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
171-
"](" +
169+
".GenericMethodOfGenericClass[V](" +
172170
"System.Collections.Generic.List`1[Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]," +
173-
"System.Collections.Generic.List`1[Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]" +
171+
"System.Collections.Generic.List`1[V]" +
174172
")"
175173
));
176174
}

Allure.Net.Commons/Functions/IdFunctions.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,29 @@ public static string CreateFullName(Type targetClass) =>
3232
/// <summary>
3333
/// Creates a string that unuquely identifies a given method.
3434
/// </summary>
35+
/// <param name="method">
36+
/// A method.
37+
/// If it's a constructed generic method, its generic definition is used instead.
38+
/// </param>
3539
/// <remarks>
3640
/// For a given test method the full name includes:
3741
/// <list type="bullet">
38-
/// <item>
39-
/// fully-qualified name of the declaring type (including type parameters)
40-
/// </item>
41-
/// <item>name of the method</item>
42-
/// <item>generic parameters of the method</item>
43-
/// <item>
44-
/// fully-qualified names of the parameter types, (including parameter
45-
/// modifiers, if any)
46-
/// </item>
42+
/// <item>assembly name</item>
43+
/// <item>namespace (if any)</item>
44+
/// <item>name of type (including its declaring types, if any)</item>
45+
/// <item>type parameters of the declaring type (for generic type definitions)</item>
46+
/// <item>type arguments of the declaring type (for constructed generic types)</item>
47+
/// <item>type parameters of the method (if any)</item>
48+
/// <item>parameter types</item>
4749
/// </list>
48-
/// A fully-qualified name of a type includes the assembly name, the
49-
/// namespace and the class name (can be a nested class).
5050
/// </remarks>
51-
public static string CreateFullName(MethodBase method)
51+
public static string CreateFullName(MethodInfo method)
5252
{
53+
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
54+
{
55+
method = method.GetGenericMethodDefinition();
56+
}
57+
5358
var className = SerializeType(method.DeclaringType);
5459
var methodName = method.Name;
5560
var typeParameters = method.GetGenericArguments();

0 commit comments

Comments
 (0)