本文整理汇总了C#中System.Reflection.Emit.DynamicMethod.GetDynamicILInfo方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicMethod.GetDynamicILInfo方法的具体用法?C# DynamicMethod.GetDynamicILInfo怎么用?C# DynamicMethod.GetDynamicILInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.DynamicMethod
的用法示例。
在下文中一共展示了DynamicMethod.GetDynamicILInfo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTokenFor_DynamicMethod
public void GetTokenFor_DynamicMethod () {
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(RuntimeMethodHandle), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
byte[] code = { 0x00, 0xd0, 0x01, 0x00, 0x00, 0x70, 0x2a };
int token0 = il.GetTokenFor(dm);
PutInteger4(token0, 0x0002, code);
il.SetCode(code, 8);
var res = dm.Invoke(null, null);
Assert.AreEqual (dm.MethodHandle, res);
}
示例2: GetTokenFor_String
public void GetTokenFor_String () {
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(string), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
byte[] code = { 0x00, 0x72, 0x01, 0x00, 0x00, 0x70, 0x2a };
int token0 = il.GetTokenFor("ABCD");
PutInteger4(token0, 0x0002, code);
il.SetCode(code, 8);
var res = dm.Invoke(null, null);
Assert.AreEqual ("ABCD", res);
}
示例3: GetTokenFor_Type
public void GetTokenFor_Type () {
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(Type), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
byte[] code = { 0x00, 0xd0, 0x01, 0x00, 0x00, 0x70, 0x28, 0x04, 0x00, 0x00, 0x0a, 0x00, 0x2a };
int token0 = il.GetTokenFor(typeof (int).TypeHandle);
int token1 = il.GetTokenFor(typeof(Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(RuntimeTypeHandle) }).MethodHandle);
PutInteger4(token0, 0x0002, code);
PutInteger4(token1, 0x0007, code);
il.SetCode(code, 8);
var res = dm.Invoke(null, null);
Assert.AreEqual (typeof (int), res);
}
示例4: GetTokenFor_Method
public void GetTokenFor_Method () {
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(string), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
// ldstr "ABCD"; call string::ToLower (); ret
byte[] code = { 0x00, 0x72, 0x01, 0x00, 0x00, 0x70, 0x28, 0x04, 0x00, 0x00, 0x0a, 0x00, 0x2a };
int token0 = il.GetTokenFor("ABCD");
int token1 = il.GetTokenFor(typeof(string).GetMethod("ToLower", Type.EmptyTypes).MethodHandle);
PutInteger4(token0, 0x0002, code);
PutInteger4(token1, 0x0007, code);
il.SetCode(code, 8);
var res = dm.Invoke(null, null);
Assert.AreEqual ("abcd", res);
}
示例5: GetTokenFor_FieldInfo
public void GetTokenFor_FieldInfo () {
aField = aField + 1;
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(RuntimeFieldHandle), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
var f = typeof (DynamicILInfoTest).GetField ("aField", BindingFlags.Static|BindingFlags.NonPublic).FieldHandle;
byte[] code = { 0x00, 0xd0, 0x01, 0x00, 0x00, 0x70, 0x2a };
int token0 = il.GetTokenFor(f);
PutInteger4(token0, 0x0002, code);
il.SetCode(code, 8);
var res = dm.Invoke(null, null);
Assert.AreEqual (f, res);
}
示例6: GetDynamicMethod
public void GetDynamicMethod () {
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(string), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
Assert.AreEqual (dm, il.DynamicMethod);
}
示例7: GetDynamicILInfo_Unique
public void GetDynamicILInfo_Unique () {
DynamicMethod dm = new DynamicMethod("HelloWorld", typeof(string), Type.EmptyTypes, typeof(DynamicILInfoTest), false);
DynamicILInfo il = dm.GetDynamicILInfo();
DynamicILInfo il2 = dm.GetDynamicILInfo();
Assert.IsTrue (Object.ReferenceEquals (il, il2));
}
示例8: ExecCodeQuery
//-------------------------------------------------------------------------------------
/// <summary>
/// Выполняет кодовый запрос на объекте.
/// </summary>
/// <param name="dstObject">Объект, на котором будет выполнен запрос.</param>
/// <param name="query">Выполняемый кодовый запрос.</param>
public static object ExecCodeQuery(object dstObject, CodeQuery query)
{
try
{
DynamicMethod dm = new DynamicMethod("DynMethod", MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard, typeof(object), new Type[] { dstObject.GetType() }, dstObject.GetType(), true);
//DynamicMethod dm = new DynamicMethod("DynMethod", null, null, dstObject.GetType(), true);
DynamicILInfo dii = dm.GetDynamicILInfo();
SignatureHelper sig = SignatureHelper.GetLocalVarSigHelper();
if(query.LocalVariables != null)
foreach(KeyValuePair<Type, bool> i in query.LocalVariables)
sig.AddArgument(i.Key, i.Value);
dii.SetLocalSignature(sig.GetSignature());
Customize(query.Body, dii, query.Schema);
dii.SetCode(query.Body, query.MaxStackSize);
DynMethod deleg = (DynMethod)dm.CreateDelegate(typeof(DynMethod), dstObject);
return deleg();
//dm.Invoke(dstObject, new object[] { dstObject });
}
catch
{
throw;
}
}
示例9: GetTokenFor_Constructor
[Test] // bug #13969
public void GetTokenFor_Constructor () {
var m = typeof (object).GetConstructor (Type.EmptyTypes);
var dm = new DynamicMethod ("Foo", typeof (void), Type.EmptyTypes);
var dil = dm.GetDynamicILInfo ();
dil.GetTokenFor (m.MethodHandle);
}