public void Emit_Ldloc_0_ReturnsValue() { var generator = new ILGenerator(); generator.DeclareLocal(typeof(int)); generator.Emit(OpCodes.Ldarg, 0); generator.Emit(OpCodes.Stloc_0); generator.Emit(OpCodes.Ldloc_0); var result = (int)generator.ExecuteUsingOneArgument(42); Assert.AreEqual(42, result); }
public void Emit_Ldarg_ReturnsArgument() { var generator = new ILGenerator(); generator.Emit(OpCodes.Ldarg, 0); var result = (int)generator.ExecuteUsingOneArgument(42); Assert.AreEqual(42, result); }
public void Emit_Nop_ThrowsException() { var generator = new ILGenerator(); generator.Emit(OpCodes.Nop); generator.ExecuteUsingOneArgument(new object[] { }); }
public void Emit_IntWithInvalidOpCode_ThrowsException() { var generator = new ILGenerator(); generator.Emit(OpCodes.Ldarg_0, 42); generator.ExecuteUsingOneArgument(new object[] { }); }
public void Emit_MethodInfoWithInvalidOpCode_ThrowsException() { var generator = new ILGenerator(); generator.Emit(OpCodes.Ldarg, (MethodInfo)null); generator.ExecuteUsingOneArgument(new object[] { }); }
public void Emit_Byte_ReturnsByte() { var generator = new ILGenerator(); generator.Emit(OpCodes.Ldc_I4_S, (byte)42); var result = (int)generator.ExecuteUsingOneArgument(new object[] { }); Assert.AreEqual(42, result); }
public void Emit_LocalBuilderWithInvalidOpCode_ThrowsException() { var generator = new ILGenerator(); var local = generator.DeclareLocal(typeof(int)); generator.Emit(OpCodes.Ldarg, local); generator.ExecuteUsingOneArgument(new object[] { }); }
public void Emit_Ldc_I4_8_ReturnsValue() { var generator = new ILGenerator(); generator.Emit(OpCodes.Ldc_I4_8); var result = (int)generator.ExecuteUsingOneArgument(new object[] { }); Assert.AreEqual(8, result); }