本文整理汇总了VB.NET中System.Reflection.Emit.AssemblyBuilder.SetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:VB.NET AssemblyBuilder.SetCustomAttribute方法的具体用法?VB.NET AssemblyBuilder.SetCustomAttribute怎么用?VB.NET AssemblyBuilder.SetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.AssemblyBuilder 的用法示例。
在下文中一共展示了AssemblyBuilder.SetCustomAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: MyAttribute
<AttributeUsage(AttributeTargets.All, AllowMultiple := False)> _
Public Class MyAttribute
Inherits Attribute
Public s As String
Public x As Integer
Public Sub New(s As String, x As Integer)
Me.s = s
Me.x = x
End Sub
End Class
Class MyApplication
Public Shared Sub Main()
Dim customAttribute As Type = CreateCallee(Thread.GetDomain())
Dim attributes As Object() = customAttribute.Assembly.GetCustomAttributes(True)
Console.WriteLine("MyAttribute custom attribute contains : ")
Dim index As Integer
For index = 0 To attributes.Length - 1
If TypeOf attributes(index) Is MyAttribute Then
Console.WriteLine("s : " + CType(attributes(index), MyAttribute).s)
Console.WriteLine("x : " + CType(attributes(index), MyAttribute).x.ToString())
Exit For
End If
Next index
End Sub
Private Shared Function CreateCallee(domain As AppDomain) As Type
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "EmittedAssembly"
Dim myAssembly As AssemblyBuilder = _
domain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
Dim myType As Type = GetType(MyAttribute)
Dim infoConstructor As ConstructorInfo = _
myType.GetConstructor(New Type(1) {GetType(String), GetType(Integer)})
Dim attributeBuilder As New CustomAttributeBuilder(infoConstructor, New Object(1) {"Hello", 2})
myAssembly.SetCustomAttribute(attributeBuilder)
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "HelloWorld" in the assembly.
Dim helloWorldClass As TypeBuilder = myModule.DefineType("HelloWorld", TypeAttributes.Public)
Return helloWorldClass.CreateType()
End Function 'CreateCallee
End Class
开发者ID:VB.NET开发者,项目名称:System.Reflection.Emit,代码行数:43,代码来源:AssemblyBuilder.SetCustomAttribute
示例2: MyAttribute
' 导入命名空间
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
<AttributeUsage(AttributeTargets.All, AllowMultiple := False)> _
Public Class MyAttribute
Inherits Attribute
Public s As Boolean
Public Sub New(s As Boolean)
Me.s = s
End Sub
End Class
Class MyApplication
Public Shared Sub Main()
Dim customAttribute As Type = CreateCallee(Thread.GetDomain())
Dim attributes As Object() = customAttribute.Assembly.GetCustomAttributes(True)
Console.WriteLine("MyAttribute custom attribute contains : ")
Dim index As Integer
For index = 0 To attributes.Length - 1
If TypeOf attributes(index) Is MyAttribute Then
Console.WriteLine("s : " + CType(attributes(index), MyAttribute).s.ToString())
Exit For
End If
Next index
End Sub
Private Shared Function CreateCallee(domain As AppDomain) As Type
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "EmittedAssembly"
Dim myAssembly As AssemblyBuilder = domain.DefineDynamicAssembly(myAssemblyName, _
AssemblyBuilderAccess.Run)
Dim myType As Type = GetType(MyAttribute)
Dim infoConstructor As ConstructorInfo = myType.GetConstructor(New Type() {GetType(Boolean)})
myAssembly.SetCustomAttribute(infoConstructor, New Byte() {01, 00, 01})
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "HelloWorld" in the assembly.
Dim helloWorldClass As TypeBuilder = myModule.DefineType("HelloWorld", TypeAttributes.Public)
Return helloWorldClass.CreateType()
End Function 'CreateCallee
End Class
开发者ID:VB.NET开发者,项目名称:System.Reflection.Emit,代码行数:46,代码来源:AssemblyBuilder.SetCustomAttribute
注:本文中的System.Reflection.Emit.AssemblyBuilder.SetCustomAttribute方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论