Solved

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

Posted on 2009-04-10
3
212 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tool Box 2 34
C# Offline Apllication 5 53
Error on Add method 1 37
Show/Hide ASP.NET controls with JQuery best practices 3 14
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

16 Experts available now in Live!

Get 1:1 Help Now