Debian Codegraph @

external/corefx/src/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetImplementationFlags.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 Xunit;
6
7 namespace System.Reflection.Emit.Tests
8 {
9 public class MethodBuilderSetImplementationFlags
10 {
11 [Theory]
12 [InlineData(MethodImplAttributes.CodeTypeMask)]
13 [InlineData(MethodImplAttributes.ForwardRef)]
14 [InlineData(MethodImplAttributes.IL)]
15 [InlineData(MethodImplAttributes.InternalCall)]
16 [InlineData(MethodImplAttributes.Managed)]
17 [InlineData(MethodImplAttributes.ManagedMask)]
18 [InlineData(MethodImplAttributes.Native)]
19 [InlineData(MethodImplAttributes.NoInlining)]
20 [InlineData(MethodImplAttributes.OPTIL)]
21 [InlineData(MethodImplAttributes.PreserveSig)]
22 [InlineData(MethodImplAttributes.Runtime)]
23 [InlineData(MethodImplAttributes.Synchronized)]
24 [InlineData(MethodImplAttributes.Unmanaged)]
25 public void SetImplementationFlags(MethodImplAttributes implementationFlags)
26 {
27 TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
28 MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Public);
29
30 method.SetImplementationFlags(implementationFlags);
31 Assert.Equal(implementationFlags, method.MethodImplementationFlags);
32 }
33
34 [Fact]
35 public void SetImplementationFlags_TypeCreated_ThrowsInvalidOperationException()
36 {
37 TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
38 MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);
39
40 type.CreateTypeInfo().AsType();
41 Assert.Throws<InvalidOperationException>(() => method.SetImplementationFlags(MethodImplAttributes.Unmanaged));
42 }
43 }
44 }