您好,登錄后才能下訂單哦!
這篇文章主要介紹了VB.NET如何自定義屬性,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
類文件:(Class1)
Imports System
Imports System.Reflection
< AttributeUsage(AttributeTargets.
All, AllowMultiple:=True,
Inherited:=True)> _Public Class Class1
Inherits System.Attribute
Private FamilyName As String
Private GivenName As String
Public Sub New(ByVal Family
Name As String)Me.FamilyName = FamilyName
End Sub
Public Overrides Function
ToString() As StringReturn String.Format("Author:
{0}{1}", FamilyName, GivenName)End Function
Public Property Family() As String
Get
Return FamilyName
End Get
Set(ByVal Value As String)
FamilyName = Value
End Set
End Property
Public Property Given() As String
Get
Return GivenName
End Get
Set(ByVal Value As String)
GivenName = Value
End Set
End Property
End Class
使用VB.NET自定義屬性的文件(Form3.VB)
< Class1("Watkins", Given:="Damien"),
Class1("Abrams")> _Public Class Form3
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender
As System.Object, ByVal e As System.
EventArgs) Handles Button1.ClickDim t As TypeType = Type.GetType
("WindowsApplication6.Form3")Dim attributes As Object() =
t.GetCustomAttributes(True)Console.WriteLine("Custom
Attributes are: ")For Each o As Object
In attributesConsole.WriteLine(o)
Next
End Sub
End Class
感謝你能夠認真閱讀完這篇文章,希望小編分享的“VB.NET如何自定義屬性”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業(yè)資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。