473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to use introspection to call method dynamically?

Let's say I have the following class:

class ccTestClass
{
public void doMethod()
{
}
}

If I have the name of the method stored in some variable x, such that String
x = "doMethod", how can I use introspection to call doMethod() dynamically
from within the code.

Thanks.

Mansi
Nov 16 '05 #1
1 9562
Hi Mansi:

Yes, you can use classes System.Reflection:

Type t = typeof(ccTestClass);

ccTestClass test = new ccTestClass();
string method = "doMethod";
Binder binder = null;
object[] invokeArgs = null;

t.InvokeMember(
method,
BindingFlags.InvokeMethod,
binder,
test,
args
);

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 26 Oct 2004 13:49:04 -0700, "Mansi"
<Ma***@discussions.microsoft.com> wrote:
Let's say I have the following class:

class ccTestClass
{
public void doMethod()
{
}
}

If I have the name of the method stored in some variable x, such that String
x = "doMethod", how can I use introspection to call doMethod() dynamically
from within the code.

Thanks.

Mansi


Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
0
by: Steven T. Hatton | last post by:
I suspect the core language is not the level at which introspection should be implemented in C++. That has been the choice of C#, and Java. Both of these languages made some trade-offs to...
4
by: Steven T. Hatton | last post by:
Has there been any substantial progress toward supporting introspection/reflection in C++? I don't intend to mean it should be part of the Standard. It would, nonetheless, be nice to have a...
9
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll;...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
0
by: Kirk McDonald | last post by:
Me again! Same project as before, if you're playing along at home. The Everything Engine model (which I am blatantly copying in my project) is that everything in the engine is a 'node,' and that...
4
by: *binarystar* | last post by:
Hello there, what method would you use to return the name of the class and/or instance introspectively eg. class Bollocks: def __init__( self ): print...
14
by: Dave Rahardja | last post by:
Is there a way to generate a series of statements based on the data members of a structure at compile time? I have a function that reverses the endianness of any data structure: /// Reverse...
4
by: mirandacascade | last post by:
Not sure if 'introspection' is the correct term, so apologies if subject line is off-base. 1) Is there any functionality that answers the question: what module am I in? 2) Is there any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.