Feedback

VB - Funktion an Hand des Names ausführen

Veröffentlicht von am 6/28/2007
(1 Bewertungen)
Hiermit können Funktionen an Hand des Names ausgeführt werden
    Public Class Scripts

        Public Shared Function getDate() As String
            Return Now
        End Function

        Public Shared Function getDate_ToLongDate() As String
            Return Now.ToLongDateString
        End Function
        Public Shared Function getDate_ToShortDate() As String
            Return Now.ToShortDateString
        End Function
        Public Shared Function getDate_ToShortTime() As String
            Return Now.ToShortTimeString
        End Function
        Public Shared Function getDate_ToLongTime() As String
            Return Now.ToLongTimeString
        End Function
        Public Shared Function getCurrentUserName() As String
        End Function
        Public Shared Function getCurrentUserID() As String
        End Function
    End Class



Public Class ScriptManager

        
        Public Shared Function getScripts() As Generic.List(Of String)

            Dim result As New Generic.List(Of String)

            Dim t As Type = GetType(Scripts)
            For Each mi As Reflection.MethodInfo In t.GetMethods
                If mi.Name <> "GetType" And mi.Name <> "ToString" And mi.Name <> "Equals" And mi.Name <> "GetHashCode" Then
                    result.Add(mi.Name)
                End If
            Next

            Return result
        End Function

        Public Shared Function getScriptResult(ByVal ScriptName As String) As String
            Dim t As Type = GetType(Scripts)
            Dim methodInfo As Reflection.MethodInfo = t.GetMethod(ScriptName)
            Dim obj As Object = Activator.CreateInstance(t)

            Dim result As String
            result = methodInfo.Invoke(obj, Nothing)

            Return result
        End Function

    End Class
Abgelegt unter Reflection.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!