Debian Codegraph @

external/corefx/src/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderIsGenericMethod.cs

raw
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 MethodBuilderIsGenericMethod
11 {
12 public static IEnumerable<object[]> IsGenericMethod_TestData()
13 {
14 TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
15
16 MethodBuilder method1 = type.DefineMethod("TestMethod1", MethodAttributes.Public);
17
18 MethodBuilder method2 = type.DefineMethod("TestMethod2", MethodAttributes.Public);
19 method2.DefineGenericParameters("T");
20
21 MethodBuilder method3 = type.DefineMethod("TestMethod3", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual, typeof(void), new Type[] { typeof(int) });
22 method3.DefineGenericParameters("T");
23 method3.DefineParameter(1, ParameterAttributes.HasDefault, "TestParam");
24
25 MethodBuilder method4 = type.DefineMethod("TestMethod4", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual, typeof(void), new Type[] { typeof(int) });
26 method4.DefineParameter(1, ParameterAttributes.HasDefault, "TestParam");
27
28 yield return new object[] { method1, false }; // Non-generic
29 yield return new object[] { method2, true }; // Generic method
30 yield return new object[] { method3, true }; // Generic parameter
31 yield return new object[] { method4, false }; // Non-generic parameter
32 }
33
34 [Theory]
35 [MemberData(nameof(IsGenericMethod_TestData))]
36 public void IsGenericMethod(MethodBuilder method, bool expected)
37 {
38 Assert.Equal(expected, method.IsGenericMethod);
39 Assert.Equal(expected, method.IsGenericMethodDefinition);
40 }
41 }
42 }