InvokeMember() problem

  • Thread starter Christian Schwarz
  • Start date
C

Christian Schwarz

Hello,

I try to call an object's member function by Type.InvokeMember() function.
It works perfectly under .NET Framework but throws an NotSupportedException
under the .NET Compact Framework. Please take a look at the following code
snippet:

public class TestClass1
{
private string m_Name;

public TestClass1(string name)
{
this.m_Name = name;
}

public string GetName()
{
return this.m_Name;
}
}

TestClass1 tc1 = new TestClass1("Meyer");
string name = (string)typeof(TestClass1).InvokeMember("GetName",
BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,
null, tc1, new object[0]);


Is the BindingFlags.InvokeMethod not supported under .NET CF ? If so, what
else could I do to call a member function dynamically and what other
limitations exist under .NET CF regarding the Type.InvokeMember() function ?

Regards, Christian
 
A

Alex Feinman [MVP]

Try this:
string name = (string)typeof(TestClass).GetMethod("GetName",
BindingFlags.Public|BindingFlags.Instance).Invoke(tc1, new object[] {} );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top