comparison Examples/Cpp/HelloWorld.cpp @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 //@ example:
2 //@ emit Emit
3 #include "stdafx.h"
4
5 using namespace System;
6
7 using namespace NUnit::Framework;
8
9 using namespace BLToolkit::Reflection;
10 using namespace BLToolkit::Reflection::Emit;
11
12 namespace Examples {
13 namespace Reflection {
14 namespace Emit
15 {
16 [TestFixture]
17 public ref class HelloWorld
18 {
19 public:
20
21 interface class IHello
22 {
23 void SayHello(String ^toWhom);
24 };
25
26 [Test]
27 void Test()
28 {
29 AssemblyBuilderHelper ^assembly = gcnew AssemblyBuilderHelper("HelloWorld.dll");
30
31 EmitHelper ^emit = assembly
32 ->DefineType ("Hello", Object::typeid, IHello::typeid)
33 ->DefineMethod(IHello::typeid->GetMethod("SayHello"))
34 ->Emitter;
35
36 emit
37 // string.Format("Hello, {0} World!", toWhom)
38 //
39 ->ldstr ("Hello, {0} World!")
40 ->ldarg_1
41 ->call (String::typeid, "Format", String::typeid, Object::typeid)
42
43 // Console.WriteLine("Hello, World!");
44 //
45 ->call (Console::typeid, "WriteLine", String::typeid)
46 ->ret()
47 ;
48
49 Type ^type = emit->Method->Type->Create();
50
51 IHello ^hello = (IHello^)TypeAccessor::CreateInstance(type);
52
53 hello->SayHello("C++");
54 }
55 };
56 }}}
57