view Source/Reflection/Emit/Examples.VB.xml @ 1:8f65451dc28f

Исправлена проблема с фабрикой и выборкой нескольких объектов в linq выражении
author cin
date Fri, 28 Mar 2014 01:04:56 +0400
parents f990fcb411a9
children
line wrap: on
line source

<?xml version="1.0" encoding="utf-8" ?>
<examples>

<emit name="Emit">
<example>
<code lang="VB">
Imports System
Imports NUnit.Framework

Imports BLToolkit.Reflection
Imports BLToolkit.Reflection.Emit

Namespace Examples.Reflection.Emit

    &lt;TestFixture()&gt; _
    Public Class HelloWorld

        Public Interface IHello
            Sub SayHello(ByVal toWhom As String)
        End Interface

        &lt;Test()&gt; _
        Sub Test()
            Dim assemblyHelper As AssemblyBuilderHelper = New AssemblyBuilderHelper("HelloWorld.dll")
            Dim typeHelper As TypeBuilderHelper = assemblyHelper.DefineType("Hello", GetType(Object), GetType(IHello))
            Dim methodHelper As MethodBuilderHelper = typeHelper.DefineMethod(GetType(IHello).GetMethod("SayHello"))
            Dim emit As EmitHelper = methodHelper.Emitter

            ' string.Format("Hello, {0} World!", toWhom)
            '
            emit _
            .ldstr("Hello, {0} World!") _
            .ldarg_1 _
            .call(GetType(String), "Format", GetType(String), GetType(Object))

            ' Console.WriteLine("Hello, World!");
            '
            emit _
            .call(GetType(Console), "WriteLine", GetType(String)) _
            .ret()

            Dim type As Type = typeHelper.Create()

            Dim hello As IHello = TypeAccessor.CreateInstance(type)

            hello.SayHello("VB")
        End Sub

    End Class

End Namespace
</code>
</example>
</emit>


</examples>