Mercurial > pub > bltoolkit
comparison Source/Reflection/Emit/Examples.VB.xml @ 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 <?xml version="1.0" encoding="utf-8" ?> | |
2 <examples> | |
3 | |
4 <emit name="Emit"> | |
5 <example> | |
6 <code lang="VB"> | |
7 Imports System | |
8 Imports NUnit.Framework | |
9 | |
10 Imports BLToolkit.Reflection | |
11 Imports BLToolkit.Reflection.Emit | |
12 | |
13 Namespace Examples.Reflection.Emit | |
14 | |
15 <TestFixture()> _ | |
16 Public Class HelloWorld | |
17 | |
18 Public Interface IHello | |
19 Sub SayHello(ByVal toWhom As String) | |
20 End Interface | |
21 | |
22 <Test()> _ | |
23 Sub Test() | |
24 Dim assemblyHelper As AssemblyBuilderHelper = New AssemblyBuilderHelper("HelloWorld.dll") | |
25 Dim typeHelper As TypeBuilderHelper = assemblyHelper.DefineType("Hello", GetType(Object), GetType(IHello)) | |
26 Dim methodHelper As MethodBuilderHelper = typeHelper.DefineMethod(GetType(IHello).GetMethod("SayHello")) | |
27 Dim emit As EmitHelper = methodHelper.Emitter | |
28 | |
29 ' string.Format("Hello, {0} World!", toWhom) | |
30 ' | |
31 emit _ | |
32 .ldstr("Hello, {0} World!") _ | |
33 .ldarg_1 _ | |
34 .call(GetType(String), "Format", GetType(String), GetType(Object)) | |
35 | |
36 ' Console.WriteLine("Hello, World!"); | |
37 ' | |
38 emit _ | |
39 .call(GetType(Console), "WriteLine", GetType(String)) _ | |
40 .ret() | |
41 | |
42 Dim type As Type = typeHelper.Create() | |
43 | |
44 Dim hello As IHello = TypeAccessor.CreateInstance(type) | |
45 | |
46 hello.SayHello("VB") | |
47 End Sub | |
48 | |
49 End Class | |
50 | |
51 End Namespace | |
52 </code> | |
53 </example> | |
54 </emit> | |
55 | |
56 | |
57 </examples> |