当前位置: 首页>>代码示例>>C#>>正文


C# DynamicMethod.GetDynamicILInfo方法代码示例

本文整理汇总了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);
	}
开发者ID:carrie901,项目名称:mono,代码行数:12,代码来源:DynamicILInfoTest.cs

示例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);
	}
开发者ID:carrie901,项目名称:mono,代码行数:12,代码来源:DynamicILInfoTest.cs

示例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);
	}
开发者ID:carrie901,项目名称:mono,代码行数:14,代码来源:DynamicILInfoTest.cs

示例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);
	}
开发者ID:carrie901,项目名称:mono,代码行数:15,代码来源:DynamicILInfoTest.cs

示例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);
	}
开发者ID:carrie901,项目名称:mono,代码行数:15,代码来源:DynamicILInfoTest.cs

示例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);
	}
开发者ID:carrie901,项目名称:mono,代码行数:5,代码来源:DynamicILInfoTest.cs

示例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));
	}
开发者ID:carrie901,项目名称:mono,代码行数:6,代码来源:DynamicILInfoTest.cs

示例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;
   }
  }
开发者ID:GoldMax,项目名称:Pulsar.NET,代码行数:35,代码来源:PulsarCodeTransfer.cs

示例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);
	}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:DynamicILInfoTest.cs


注:本文中的System.Reflection.Emit.DynamicMethod.GetDynamicILInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。