Multimobile Development: Building Applications for any Smartphone
Type.InvokeMember on indexed properties and array fields
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.


Guven Demir
Hi,

The help for Type.InvokeMethod() has the following code sample for reading an indexed property:

===

//Get an indexed property value
int index = 3;
result = t.InvokeMember ("Item",
BindingFlags.Default |
BindingFlags.GetProperty,
null, c, new object [] {index});
Console.WriteLine ("Item[{0}] == {1}", index, result);

===

I have a similar situation in my own class but when I use very similar code I get a MissingMethodException. My member is an instance of a sub class of my class which has an indexer. Something like:

===

class Foo
{
public class Bar
{
private int[] prInts=new int[] {1, 2, 3};

public int this[int index] { return prInts[index]; }
}

public Bar Integers=new Bar();
}

===

Then I use a code like

===

Foo obj = new Foo();
Type t = typeof(Foo);
int index = 2;
object result = t.InvokeMember ("Item",
BindingFlags.Default |
BindingFlags.GetProperty,
null, obj, new object [] {index});

===

which results in a MissingMethodException.

The same problem applies for array fields.

Any ideas? Thanks in advance.
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Nicholas Paldino [MVP]
Guven,

Use the Instance binding flag. It says in the documentation that either
the Instance or Static member of the BindingFlags enumeration needs to be
specified.

Hope this helps.

--
- Nicholas Paldino [MVP]
- Click here to reveal e-mail address

"Guven Demir" <_abidik_@_mail_._com_> wrote in message
news:3BFAEFFC.7FD302A6@_mail_._com_...
[Original message clipped]

of my class which has an indexer. Something like:
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
 
System.Console
System.MissingMethodException
System.Reflection.BindingFlags
System.Type




Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734