Solved

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

Posted on 2009-04-10
3
215 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 500 total points
ID: 24121024
0
 

Author Closing Comment

by:NBAIS
ID: 31569143
Thank you!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name Space error VS2015 1 37
VB.Net SQL Query 2 Tables Different Databases 3 47
c#, case, if 4 22
SQL Server Serialization error 8 15
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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