本文整理匯總了VB.NET中System.Reflection.Emit.AssemblyBuilder.DefineUnmanagedResource方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET AssemblyBuilder.DefineUnmanagedResource方法的具體用法?VB.NET AssemblyBuilder.DefineUnmanagedResource怎麽用?VB.NET AssemblyBuilder.DefineUnmanagedResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Reflection.Emit.AssemblyBuilder
的用法示例。
在下文中一共展示了AssemblyBuilder.DefineUnmanagedResource方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
Friend Shared Sub Main()
Dim myAssembly As AssemblyBuilder = _
CreateAssembly("MyEmitTestAssembly")
' Defines a standalone managed resource for this assembly.
Dim myResourceWriter As IResourceWriter = _
myAssembly.DefineResource("myResourceFile", _
"A sample Resource File", "MyAssemblyResource.resources", _
ResourceAttributes.Private)
myResourceWriter.AddResource("AddResource Test", "Testing for the added resource")
myAssembly.Save(myAssembly.GetName().Name & ".dll")
' Defines an unmanaged resource file for this assembly.
myAssembly.DefineUnmanagedResource("MyAssemblyResource.resources")
End Sub
Private Shared Function CreateAssembly(ByVal name As String) As AssemblyBuilder
Dim aName As New AssemblyName(name)
Dim myAssembly As AssemblyBuilder = _
AppDomain.CurrentDomain.DefineDynamicAssembly(aName, _
AssemblyBuilderAccess.Save)
' Define a dynamic module.
Dim myModule As ModuleBuilder = _
myAssembly.DefineDynamicModule(aName.Name, aName.Name & ".dll")
' Define a public class named "EmitClass" in the assembly.
Dim myEmitClass As TypeBuilder = _
myModule.DefineType("EmitClass", TypeAttributes.Public)
' Define the Display method.
Dim myMethod As MethodBuilder = _
myEmitClass.DefineMethod("Display", MethodAttributes.Public, _
GetType(String), Nothing)
' Generate IL for Display method.
Dim methodIL As ILGenerator = myMethod.GetILGenerator()
methodIL.Emit(OpCodes.Ldstr, "Display method get called.")
methodIL.Emit(OpCodes.Ret)
myEmitClass.CreateType()
Return myAssembly
End Function
示例2: MyAssemblyResource
' 導入命名空間
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Resources
Public Class MyAssemblyResource
Friend Shared Sub Main()
Dim myAssembly As AssemblyBuilder = _
CreateAssembly("MyEmitTestAssembly")
' Defines a standalone managed resource for this assembly.
Dim myResourceWriter As IResourceWriter = _
myAssembly.DefineResource("myResourceFile", _
"A sample Resource File", "MyAssemblyResource.resources", _
ResourceAttributes.Private)
myResourceWriter.AddResource("AddResource Test", "Testing for the added resource")
myAssembly.Save(myAssembly.GetName().Name & ".dll")
' Defines an unmanaged resource file for this assembly.
myAssembly.DefineUnmanagedResource(New Byte() {1, 0, 1})
End Sub
Private Shared Function CreateAssembly(ByVal name As String) As AssemblyBuilder
Dim aName As New AssemblyName(name)
Dim myAssembly As AssemblyBuilder = _
AppDomain.CurrentDomain.DefineDynamicAssembly(aName, _
AssemblyBuilderAccess.Save)
' Define a dynamic module.
Dim myModule As ModuleBuilder = _
myAssembly.DefineDynamicModule(aName.Name, aName.Name & ".dll")
' Define a public class named "EmitClass" in the assembly.
Dim myEmitClass As TypeBuilder = _
myModule.DefineType("EmitClass", TypeAttributes.Public)
' Define the Display method.
Dim myMethod As MethodBuilder = _
myEmitClass.DefineMethod("Display", MethodAttributes.Public, _
GetType(String), Nothing)
' Generate IL for Display method.
Dim methodIL As ILGenerator = myMethod.GetILGenerator()
methodIL.Emit(OpCodes.Ldstr, "Display method get called.")
methodIL.Emit(OpCodes.Ret)
myEmitClass.CreateType()
Return myAssembly
End Function
End Class