VB.Net Tutorial/Reflection/MethodInfo

Материал из VB Эксперт
Версия от 12:54, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Use Reflection to get all member names

Module Module1
    Class Book
        Public Title As String
        Public Author As String
        Public Price As Double
        Public Sub New(ByVal Title As String, ByVal Author As String, ByVal Price As Double)
            Me.Title = Title
            Me.Author = Author
            Me.Price = Price
        End Sub
        Public Sub ShowTitle()
            Console.WriteLine("Title: " & Title)
        End Sub
        Public Sub ShowBook()
            Console.WriteLine("Title: " & Title)
            Console.WriteLine("Author: " & Author)
            Console.WriteLine("Price: " & Price)
        End Sub
    End Class
    Sub Main()
        Dim NetBook As New Book("AAA","BBB", 49.99)
        Console.WriteLine("Member Names")
        Dim Member As Reflection.MemberInfo
        For Each Member In NetBook.GetType.GetMembers()
            Console.WriteLine(Member.Name)
        Next
    End Sub
End Module
Member Names
ShowTitle
ShowBook
GetType
ToString
Equals
GetHashCode
.ctor
Title
Author
Price

Use Reflection to get all method names

Module Module1
    Class Book
        Public Title As String
        Public Author As String
        Public Price As Double
        Public Sub New(ByVal Title As String, ByVal Author As String, ByVal Price As Double)
            Me.Title = Title
            Me.Author = Author
            Me.Price = Price
        End Sub
        Public Sub ShowTitle()
            Console.WriteLine("Title: " & Title)
        End Sub
        Public Sub ShowBook()
            Console.WriteLine("Title: " & Title)
            Console.WriteLine("Author: " & Author)
            Console.WriteLine("Price: " & Price)
        End Sub
    End Class
    Sub Main()
        Dim NetBook As New Book("AAA","BBB", 49.99)
        Console.WriteLine("Method Names")
        Dim Info As Reflection.MethodInfo
        For Each Info In NetBook.GetType.GetMethods()
            Console.WriteLine(Info.Name)
        Next
    End Sub
End Module
Method Names
ShowTitle
ShowBook
GetType
ToString
Equals
GetHashCode