本文整理汇总了VB.NET中System.ObsoleteAttribute.IsError属性的典型用法代码示例。如果您正苦于以下问题:VB.NET ObsoleteAttribute.IsError属性的具体用法?VB.NET ObsoleteAttribute.IsError怎么用?VB.NET ObsoleteAttribute.IsError使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.ObsoleteAttribute 的用法示例。
在下文中一共展示了ObsoleteAttribute.IsError属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Reflection
Public Module Example
' Mark OldProperty As Obsolete.
<ObsoleteAttribute("This property is obsolete. Use NewProperty instead.", False)>
Public ReadOnly Property OldProperty As String
Get
Return "The old property value."
End Get
End Property
Public ReadOnly Property NewProperty As String
Get
Return "The new property value."
End Get
End Property
' Mark OldMethod As Obsolete.
<ObsoleteAttribute("This method is obsolete. Call NewMethod instead.", True)>
Public Function OldMethod() As String
Return "You have called OldMethod."
End Function
Public Function NewMethod() As String
Return "You have called NewMethod."
End Function
Public Sub Main()
' Get all public members of this type.
Dim members() As MemberInfo = GetType(Example).GetMembers()
' Count total obsolete members.
Dim n As Integer = 0
' Try to get the ObsoleteAttribute for each public member.
Console.WriteLine("Obsolete members in the Example class:")
Console.WriteLine()
For Each member In members
Dim attribs() As ObsoleteAttribute = CType(member.GetCustomAttributes(GetType(ObsoleteAttribute),
False), ObsoleteAttribute())
If attribs.Length > 0 Then
Dim attrib As ObsoleteAttribute = attribs(0)
Console.WriteLine("Member Name: {0}.{1}", member.DeclaringType.FullName, member.Name)
Console.WriteLine(" Message: {0}", attrib.Message)
Console.WriteLine(" Warning/Error: {0}", if(attrib.IsError, "Error", "Warning"))
n += 1
End If
Next
If n = 0 Then
Console.WriteLine("The Example type has no obsolete attributes.")
End If
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:54,代码来源:ObsoleteAttribute.IsError 输出:
Obsolete members in the Example class:
Member Name: Example.OldMethod
Message: This method is obsolete. Call NewMethod instead.
Warning/Error: Error
Member Name: Example.OldProperty
Message: This property is obsolete. Use NewProperty instead.
Warning/Error: Warning
注:本文中的System.ObsoleteAttribute.IsError属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论