Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

InvokeMethod - Invoking a method via reflection

Total Hit ( 2735)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' Invoke a method via reflection and return its result - return null if method
' doesn't exist or throws
' Note: requires Imports System.Reflection
'
' Example:
'  Function GetCompleteName(ByVal firstName As String,
' ByVal lastName As String)
'    Return lastName & ", " & firstName
'  End Function
'  ...
'  MessageBox.Show(InvokeMethod(Me, "GetCompleteName", False, "Marco",
' "Bellinaso"))

Function InvokeMethod(ByVal obj As Object, ByVal methodName As String, _
  ByVal throwIfError As Boolean, ByVal ParamArray args() As Object) As Object
  Try
    Return obj.GetType().InvokeMember(methodName, BindingFlags.Instance Or _
      BindingFlags.InvokeMethod Or BindingFlags.Public, Nothing, obj, _
      args)
  Catch ex As Exception
    If throwIfError Then Throw ex
  End Try
  ' if method doesn't exists or throws
  Return Nothing
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.