public void TestLdarga2() { var method = new DynamicMethod(Guid.NewGuid().ToString(), typeof(void), new[] { typeof(int), typeof(int) }, typeof(TestArgumentOutOfRange)); var il = new GroboIL(method); il.Ldarga(0); il.Ldarga(1); Assert.Throws <ArgumentOutOfRangeException>(() => il.Ldarga(2)); }
private void LoadTupleField(GroboIL il, ValueTupleField tupleFiled) { il.Ldstr(tupleFiled.NameInUserCode); il.Ldarga(0); il.Ldfld(tupleFiled.FieldInfo); if (tupleFiled.FieldInfo.FieldType.IsValueType) { il.Box(tupleFiled.FieldInfo.FieldType); } }
private DynamicMethod BuildAccessorMethod() { var assertMethod = typeof(TestGrobufUsages).GetMethod("AssertDateTimeOffsetFields", BindingFlags.Static | BindingFlags.NonPublic); var method = new DynamicMethod("Grobuf_Write_DateTimeOffset_" + Guid.NewGuid(), typeof(void), new[] { dateTimeOffsetType }, typeof(TestGrobufUsages), true); using (var il = new GroboIL(method)) { il.Ldarga(0); // stack: [obj] il.Ldfld(GetDateTimeOffsetField("_dateTime", "m_dateTime")); // stack: [obj.m_dateTime] il.Ldarga(0); // stack: [obj] il.Ldfld(GetDateTimeOffsetField("_offsetMinutes", "m_offsetMinutes")); // stack: [obj.m_offsetMinutes] il.Call(assertMethod); // stack: [] il.Ret(); } return(method); }
public void TestConstrained() { var method = new DynamicMethod(Guid.NewGuid().ToString(), typeof(string), new[] { typeof(int) }, typeof(string), true); using (var il = new GroboIL(method)) { il.Ldarga(0); il.Call(typeof(object).GetMethod("ToString"), typeof(int)); il.Ret(); Console.WriteLine(il.GetILCode()); } }
public void TestByRefGeneric() { var assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run); var module = assembly.DefineDynamicModule(Guid.NewGuid().ToString()); var type = module.DefineType("Zzz", TypeAttributes.Class | TypeAttributes.Public); var method = type.DefineMethod("Qzz", MethodAttributes.Public | MethodAttributes.Static); var genericParameters = method.DefineGenericParameters("TZzz"); var parameter = genericParameters[0]; method.SetParameters(parameter); method.SetReturnType(typeof(void)); using (var il = new GroboIL(method)) { il.Ldarga(0); il.Call(HackHelpers.GetMethodDefinition <int>(x => F(ref x)).GetGenericMethodDefinition().MakeGenericMethod(parameter)); il.Ret(); Console.Write(il.GetILCode()); } }