Topaz Filer - Email filing software
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...
 
New BootFX DBGet build available
Twitter and Snow… simple #uksnow
 
    
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...
 
Windows 7 compatible tool for mounting ISO images
Introduction to BootFX’s Object Relational Mapping Functionality article now live on CodeProject
 
 
System.Console
System.MissingMethodException
System.Reflection.BindingFlags
System.Type




Ad
BootFX
Reliable and powerful .NET application framework.
Looking to invest in a major software project? Technical and commercial advice available here.
Other Helpful Sites
MBR 247
Topaz Filer
SharePoint Email Filing
Software Advisory Services
 
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