Reflexion

D

Damien DORISON

Hi all,

i try to call InvokeMember on a type for a property. This works fine
for .Net Framwork 1.1 but generates an exception
"NotSupportedException" for Compact Framework. It works also fine when
invoking a method (instead of a property) on the Compact Framework.

This is not documented in VS documentation, so, is there a probleme
with my calling (code sample is bellow) or is InvokeMember not
implemented on CompactFramework for properties.

Many thanks,

Damien

// Class to Reflect
public class Class1
{
public int MyProperty
{
get
{
return 12;
}
}
}
}

// Call for reflexion
Assembly a = Assembly.GetExecutingAssembly();
Type t = a.GetType("Class1");
object ob = a.CreateInstance("Class1");
try
{
object o = t.InvokeMember("MyProperty", BindingFlags.Default |
BindingFlags.GetProperty, null, ob, new object[] {});
}
catch(Exception ee)
{
string s = ee.Message;
}
 
A

Alex Feinman [MVP]

Generic Type.InvokeMember is not fully supported in CF. Use Invoke (or
GetValue/SetValue) method on the member itself, such as field, property,
constructor, method etc:

myObj.GetType().GetProperty("MyProp").GetValue(myObj);
 

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