473,397 Members | 2,099 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,397 software developers and data experts.

using reflection to invoke static methods of the class

Say, I have classname string, static method string, parameters list
(which is char[]). Can I use reflection to invoke the method?
Oct 16 '08 #1
4 5792
On Thu, 16 Oct 2008 13:33:56 -0700, puzzlecracker <ir*********@gmail.com>
wrote:
Say, I have classname string, static method string, parameters list
(which is char[]). Can I use reflection to invoke the method?
Yes.
Oct 16 '08 #2
On Oct 16, 10:33*pm, puzzlecracker <ironsel2...@gmail.comwrote:
Say, I have classname string, static *method string, parameters list
(which is char[]). Can I use reflection to invoke the method?
Yes.
Using Type.GetType("YOUR-TYPE").InvokeMember
The second parameter is BindingFlag, specify BindingFlags.Static for
invocation of static methods.

--sternr
Oct 16 '08 #3
puzzlecracker wrote:
Say, I have classname string, static method string, parameters list
(which is char[]). Can I use reflection to invoke the method?
Yes.

Example:

using System;
using System.Reflection;

namespace E
{
public class Program
{
public static void Test(char[] ca)
{
foreach(char c in ca)
{
Console.Write(c);
}
Console.WriteLine();
}
public static void Main(string[] args)
{
typeof(Program).InvokeMember("Test",
BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static |
BindingFlags.InvokeMethod, null, null, new object[] { new char[] { 'H',
'e', 'l', 'l', 'o' }});
Console.ReadKey();
}
}
}

Arne
Oct 16 '08 #4
puzzlecracker wrote:
Say, I have classname string, static method string, parameters list
(which is char[]). Can I use reflection to invoke the method?
Are you referring to a constructor (method name == class name)? Yes you can
use reflection, no most of the code suggested to you isn't going to work
exactly the same for constructor calls.
Oct 20 '08 #5

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

Similar topics

1
by: Derek Hart | last post by:
I have the following code: Me.GetType().InvokeMember(FunctionToRun, BindingFlags.InvokeMethod, Nothing, Me, params) I can send in a string from a database into the FunctionToRun variable, and...
6
by: kapilp | last post by:
hi, i have a program that used reflection to execute methods. now i want to execute the reflected method on a new thread but cant figure out how or if it can be done. take the below code, for...
0
by: samlee | last post by:
Hi All, I'm learning how to write C# using reflection, but don't know how to code using reflection this.Controls.Add(this.label1); Could anyone help, Thank in advance. ...
3
by: Manfred Braun | last post by:
Hi All, I am able to invoke some methods from an instance of a loaded assembly, but I am not able to invoke the loaded assemblie's "Main" method. I try it this way: Assembly assembly =...
2
by: Doug Handler | last post by:
I'm trying to invoke a method that returns a value (actually a Panel), but i keep getting an error: System.Reflection.TargetException was unhandled Message="Object does not match target type." ...
5
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
2
by: mswlogo | last post by:
I looked high and low for code to do this and finally found some VB code that did it right. This is a C# flavor of it. public event EventHandler<EventArgsMyEventToBeFired; public void...
6
by: chandramohanp | last post by:
Hi I am trying to modify class instance members using reflection. I am having problem when trying to add/remove/display elements related to List<int> member. Following is the code. class...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.