-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
LocalBuilderLocalIndex.cs
35 lines (32 loc) · 1.3 KB
/
LocalBuilderLocalIndex.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Reflection.Emit.Tests
{
public class LocalBuilderLocalIndex
{
[Fact]
public void LocalIndex_FirstLocal_ReturnsZero()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
MethodBuilder method = type.DefineMethod("Method", MethodAttributes.Public);
ILGenerator ilGenerator = method.GetILGenerator();
ilGenerator.Emit(OpCodes.Ret);
LocalBuilder localBuilder = ilGenerator.DeclareLocal(typeof(string));
Assert.Equal(0, localBuilder.LocalIndex);
}
[Fact]
public void LocalIndex_MultipleLocals_ReturnsIndex()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
MethodBuilder method = type.DefineMethod("Method", MethodAttributes.Public);
ILGenerator ilGenerator = method.GetILGenerator();
ilGenerator.Emit(OpCodes.Ret);
for (int i = 0; i < 1000; i++)
{
LocalBuilder localBuilder = ilGenerator.DeclareLocal(typeof(char));
Assert.Equal(i, localBuilder.LocalIndex);
}
}
}
}