VB.NET自定义属性应用方式解析

开发 后端
我们可以使用VB.NET自定义属性的文件进行具体的代码编写,完成程序中需要的特定功能。在这里就为大家详细介绍相关应用方法。

VB.NET编程语言的出现,在一定程度上改变了编程人员的编写习惯,它灵活的编写方式提高了编程效率。我们在这里就会为大家带来关于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 String   
Return 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  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.

使用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.Click   
Dim 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 attributes   
Console.WriteLine(o)    Next    End Sub    End Class  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

VB.NET自定义属性的具体应用方式就为大家介绍到这里。

【编辑推荐】

  1. VB.NET异常迭代捕捉代码示例
  2. VB.NET共享成员变量创建技巧解析
  3. 范例解读VB.NET获取环境变量
  4. VB.NET抓取网页相关问题解决方法
  5. VB.NET读取内存具体代码编写方法
责任编辑:曹凯 来源: blue1000.com
相关推荐

2010-01-15 15:26:46

VB.NET自定义类型

2009-10-09 15:59:41

VB.NET对象

2010-01-19 13:36:16

VB.NET可选参数

2010-01-11 17:40:36

VB.NET相框效果

2009-10-27 11:16:20

VB.NET应用框架

2010-01-15 15:03:23

VB.NET对象变量声

2010-01-11 17:58:36

VB.NET压缩ZIP

2010-01-20 17:41:13

VB.NET标记语句

2010-01-14 18:08:08

VB.NET抽象类

2010-01-12 18:12:58

VB.NET事件

2010-01-21 18:19:45

VB.NET条件编译

2010-01-22 16:07:26

VB.NET Mid函

2009-11-10 17:12:22

VB.NET自定义类型

2009-10-26 15:26:37

VB.NET属性

2010-01-21 13:11:31

VB.NET安装工程

2009-10-14 11:15:06

VB.NET Grou

2009-10-13 09:24:57

VB.NET Dock

2009-10-28 10:51:32

VB.NET默认属性

2010-01-15 16:46:05

VB.NET集合存储

2009-11-02 14:48:45

VB.NET HOOK
点赞
收藏

51CTO技术栈公众号