当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET AssemblyBuilder.DefineUnmanagedResource方法代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Reflection.Emit,代码行数:50,代码来源:AssemblyBuilder.DefineUnmanagedResource

示例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
开发者ID:VB.NET开发者,项目名称:System.Reflection.Emit,代码行数:59,代码来源:AssemblyBuilder.DefineUnmanagedResource


注:本文中的System.Reflection.Emit.AssemblyBuilder.DefineUnmanagedResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。