Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-10
3
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 total points
ID: 24121024
0
 

Author Closing Comment

by:NBAIS
ID: 31569143
Thank you!
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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