Say, I have classname string, static method string, parameters list
(which is char[]). Can I use reflection to invoke the method? 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.
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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.
...
|
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 =...
|
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."
...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |