| 1 |
// Licensed to the .NET Foundation under one or more agreements. |
| 2 |
// The .NET Foundation licenses this file to you under the MIT license. |
| 3 |
// See the LICENSE file in the project root for more information. |
| 4 |
|
| 5 |
using System.Collections.Generic; |
| 6 |
using Xunit; |
| 7 |
|
| 8 |
namespace System.Reflection.Emit.Tests |
| 9 |
{ |
| 10 |
public class MethodBuilderGetHashCode |
| 11 |
{ |
| 12 |
public static IEnumerable<object[]> GetHashCode_TestData() |
| 13 |
{ |
| 14 |
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract); |
| 15 |
|
| 16 |
MethodBuilder method1 = type.DefineMethod("TestMethod1", MethodAttributes.Public); |
| 17 |
MethodBuilder method2 = type.DefineMethod("TestMethod1", MethodAttributes.Public); |
| 18 |
|
| 19 |
MethodBuilder method3 = type.DefineMethod("TestMethod1", MethodAttributes.Public); |
| 20 |
method3.DefineGenericParameters("T", "U"); |
| 21 |
|
| 22 |
MethodBuilder method4 = type.DefineMethod("TestMethod1", MethodAttributes.Public); |
| 23 |
method4.DefineGenericParameters("T", "U"); |
| 24 |
|
| 25 |
MethodBuilder method5 = type.DefineMethod("TestMethod2", MethodAttributes.Public); |
| 26 |
|
| 27 |
yield return new object[] { method1, method2, true }; // Non-generic |
| 28 |
yield return new object[] { method3, method4, true }; // Generic |
| 29 |
yield return new object[] { method1, method5, false }; // Different names |
| 30 |
} |
| 31 |
|
| 32 |
[Theory] |
| 33 |
[MemberData(nameof(GetHashCode_TestData))] |
| 34 |
public void GetHashCode(MethodBuilder method1, MethodBuilder method2, bool expected) |
| 35 |
{ |
| 36 |
Assert.Equal(expected, method1.GetHashCode().Equals(method2.GetHashCode())); |
| 37 |
} |
| 38 |
} |
| 39 |
} |