Solved

Calling a Method by it's string name and pass variables

Posted on 2009-04-10
3
211 Views
Last Modified: 2013-12-17
How do I use the following system.reflection code to call a method by it's string name and pass that method a variable?

Imports System.Reflection

Public Class Reflect

    Public Shared Function ExecuteMethod(ByVal name As String, ByVal parameters() As Object) As Object
        Dim assy As Assembly = [Assembly].GetExecutingAssembly()
        Dim ns As String = assy.GetType().Namespace

        Dim method As MethodInfo = assy.GetType().GetMethod(ns & "." & name)
        Return method.Invoke(Nothing, parameters)
    End Function

End Class
0
Comment
Question by:NBAIS
3 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24121003
This isn't the answer that you want to hear I'm sure, but it's likely the best answer for you nonetheless:

If you working on a project that had some special case where you actually needed to do this, then you would also have enough experience to read the documentation and learn how to do it for yourself.  The very fact that you are asking this question tells me that whatever you are trying to do could be implemented in a better way.

Someone else will probably answer your question more directly, but that doesn't mean that they've given you the right answer for what you need to do.

Good luck.
0
 
LVL 16

Accepted Solution

by:
CuteBug earned 500 total points
ID: 24121024
0
 

Author Closing Comment

by:NBAIS
ID: 31569143
Thank you!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now