本文整理汇总了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