本文整理汇总了VB.NET中System.Web.Services.Protocols.LogicalMethodInfo.ReturnTypeCustomAttributeProvider属性的典型用法代码示例。如果您正苦于以下问题:VB.NET LogicalMethodInfo.ReturnTypeCustomAttributeProvider属性的具体用法?VB.NET LogicalMethodInfo.ReturnTypeCustomAttributeProvider怎么用?VB.NET LogicalMethodInfo.ReturnTypeCustomAttributeProvider使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了LogicalMethodInfo.ReturnTypeCustomAttributeProvider属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MyAttribute
' 导入命名空间
Imports System.Reflection
Imports System.Web.Services.Protocols
' Define a custom attribute with one named parameter.
<AttributeUsage(AttributeTargets.Method Or AttributeTargets.ReturnValue, AllowMultiple := True)> _
Public Class MyAttribute
Inherits Attribute
Private myName As String
Public Sub New(name As String)
myName = name
End Sub
Public ReadOnly Property Name() As String
Get
Return myName
End Get
End Property
End Class
Public Class MyService
<MyAttribute("This is the first sample attribute"), MyAttribute("This is the second sample attribute")> _
Public Function Add(xValue As Integer, yValue As Integer) _
As<MyAttribute("This is the return sample attribute")> Integer
Return xValue + yValue
End Function 'Add
End Class
Public Class LogicalMethodInfo_GetCustomAttribute
Public Shared Sub Main()
Dim myType As Type = GetType(MyService)
Dim myMethodInfo As MethodInfo = myType.GetMethod("Add")
' Create a synchronous 'LogicalMethodInfo' instance.
Dim myLogicalMethodInfo As LogicalMethodInfo = _
LogicalMethodInfo.Create(New MethodInfo() {myMethodInfo}, LogicalMethodTypes.Sync)(0)
' Display the method for which the attributes are being displayed.
Console.WriteLine(ControlChars.NewLine + "Displaying the attributes for the method : {0}" + _
ControlChars.NewLine, myLogicalMethodInfo.MethodInfo.ToString())
' Displaying a custom attribute of type 'MyAttribute'
Console.WriteLine(ControlChars.NewLine + "Displaying attribute of type 'MyAttribute'" + _
ControlChars.NewLine)
Dim attribute As Object = myLogicalMethodInfo.GetCustomAttribute(GetType(MyAttribute))
Console.WriteLine(CType(attribute, MyAttribute).Name)
' Display all custom attribute of type 'MyAttribute'.
Console.WriteLine(ControlChars.NewLine + "Displaying all attributes of type 'MyAttribute'" + _
ControlChars.NewLine)
Dim attributes As Object() = myLogicalMethodInfo.GetCustomAttributes(GetType(MyAttribute))
Dim i As Integer
For i = 0 To attributes.Length - 1
Console.WriteLine(CType(attributes(i), MyAttribute).Name)
Next i
' Display all return attributes of type 'MyAttribute'.
Console.WriteLine(ControlChars.NewLine + "Displaying all return attributes of type 'MyAttribute'" + _
ControlChars.NewLine)
Dim myCustomAttributeProvider As ICustomAttributeProvider = _
myLogicalMethodInfo.ReturnTypeCustomAttributeProvider
If myCustomAttributeProvider.IsDefined(GetType(MyAttribute), True) Then
attributes = myCustomAttributeProvider.GetCustomAttributes(True)
For i = 0 To attributes.Length - 1
If attributes(i).GetType().Equals(GetType(MyAttribute)) Then
Console.WriteLine(CType(attributes(i), MyAttribute).Name)
End If
Next i
End If ' Display all the custom attributes of type 'MyAttribute'.
Console.WriteLine(ControlChars.NewLine + "Displaying all attributes of type 'MyAttribute'" + _
ControlChars.NewLine)
myCustomAttributeProvider = myLogicalMethodInfo.CustomAttributeProvider
If myCustomAttributeProvider.IsDefined(GetType(MyAttribute), True) Then
attributes = myCustomAttributeProvider.GetCustomAttributes(True)
For i = 0 To attributes.Length - 1
If attributes(i).GetType().Equals(GetType(MyAttribute)) Then
Console.WriteLine(CType(attributes(i), MyAttribute).Name)
End If
Next i
End If
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Web.Services.Protocols,代码行数:86,代码来源:LogicalMethodInfo.ReturnTypeCustomAttributeProvider