|
| 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.
|
|
|
| |
|
| |
| |
| 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]
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|