Mercurial > pub > bltoolkit
view Examples/CS/Reflection.Emit/HelloWorld.cs @ 5:f7d63a092920
Исправлено условие Where в тех случаях, когда репозитарий не является генериком
author | cin |
---|---|
date | Tue, 10 Mar 2015 16:02:11 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
//@ example: //@ emit Emit using System; using NUnit.Framework; using BLToolkit.Reflection; using BLToolkit.Reflection.Emit; namespace Examples.Reflection.Emit { [TestFixture] public class HelloWorld { public interface IHello { void SayHello(string toWhom); } [Test] public void Test() { EmitHelper emit = new AssemblyBuilderHelper("HelloWorld.dll") .DefineType ("Hello", typeof(object), typeof(IHello)) .DefineMethod(typeof(IHello).GetMethod("SayHello")) .Emitter; /*[a]*/emit/*[/a]*/ // string.Format("Hello, {0}!", toWhom) // ./*[a]*/ldstr/*[/a]*/ ("Hello, {0}!") ./*[a]*/ldarg_1/*[/a]*/ ./*[a]*/call/*[/a]*/ (typeof(string), "Format", typeof(string), typeof(object)) // Console.WriteLine("Hello, World!"); // ./*[a]*/call/*[/a]*/ (typeof(Console), "WriteLine", typeof(string)) ./*[a]*/ret/*[/a]*/() ; Type type = emit.Method.Type.Create(); IHello hello = (IHello)TypeAccessor.CreateInstance(type); hello.SayHello("World"); } } }