Click here to Skip to main content
15,893,668 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error converting Int64 to Int32 and vice versa Pin
JoeRip24-Jul-08 10:44
JoeRip24-Jul-08 10:44 
QuestionCan you get the resualt? help me, please! Pin
sgncdc23-Jul-08 17:56
sgncdc23-Jul-08 17:56 
AnswerRe: Can you get the resualt? help me, please! Pin
half-life23-Jul-08 19:41
half-life23-Jul-08 19:41 
AnswerRe: Can you get the resualt? help me, please! Pin
sgncdc23-Jul-08 20:25
sgncdc23-Jul-08 20:25 
GeneralRe: Can you get the resualt? help me, please! Pin
Guffa23-Jul-08 23:18
Guffa23-Jul-08 23:18 
AnswerRe: Can you get the resualt? help me, please! Pin
Christian Graus23-Jul-08 23:41
protectorChristian Graus23-Jul-08 23:41 
QuestionProblems when I update database from a xml file Pin
dienhuflit23-Jul-08 17:51
dienhuflit23-Jul-08 17:51 
AnswerRe: Problems when I update database from a xml file Pin
half-life23-Jul-08 19:57
half-life23-Jul-08 19:57 
GeneralRe: Problems when I update database from a xml file Pin
dienhuflit24-Jul-08 15:23
dienhuflit24-Jul-08 15:23 
QuestionData storage and Uploading file Pin
Banjo Ayorinde23-Jul-08 17:13
Banjo Ayorinde23-Jul-08 17:13 
AnswerRe: Data storage and Uploading file Pin
half-life23-Jul-08 19:53
half-life23-Jul-08 19:53 
GeneralRe: Data storage and Uploading file Pin
Abdul Sami X24-Jul-08 20:15
Abdul Sami X24-Jul-08 20:15 
QuestionCopy Dictionay Object To Other [modified] Pin
vaibhav.jape@gmail.com23-Jul-08 13:30
vaibhav.jape@gmail.com23-Jul-08 13:30 
AnswerRe: Copy Dictionay Object To Other Pin
N a v a n e e t h23-Jul-08 17:01
N a v a n e e t h23-Jul-08 17:01 
GeneralRe: Copy Dictionay Object To Other Pin
vaibhav.jape@gmail.com23-Jul-08 17:20
vaibhav.jape@gmail.com23-Jul-08 17:20 
AnswerRe: Copy Dictionay Object To Other [modified] Pin
Elroy Dsilva23-Jul-08 17:10
Elroy Dsilva23-Jul-08 17:10 
AnswerRe: Copy Dictionay Object To Other Pin
Elroy Dsilva23-Jul-08 17:37
Elroy Dsilva23-Jul-08 17:37 
AnswerRe: Copy Dictionay Object To Other Pin
N a v a n e e t h23-Jul-08 19:30
N a v a n e e t h23-Jul-08 19:30 
QuestionHow to access an IEnumerable item using reflection [modified] Pin
Clive D. Pottinger23-Jul-08 12:39
Clive D. Pottinger23-Jul-08 12:39 
Hello folks.

It's been a while since I've managed to paint myself into a corner - but have no fear - I have not lost my talent for getting in over my head!

This time I am working with reflection and trying to access different classes generically . But I have run into a problem trying to get some information out of an object when the object's class isn't known until runtime:

public void GetDataFromStaticClassX(string MethodToCall, object[]MethodParms)
{  
  private const BindingFlags StaticMethodBindings = BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod;
  private const BindingFlags InstancePropertyBindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
  private const BindingFlags InstanceMethodBindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;


  object returnedInfo = typeof(X).InvokeMember(MethodToCall, StaticMethodBindings, null, null, MethodParms);

That works: the proper method is called and the result is put in returnedInfo. However, the result could be any of a number of different classes, depending on the value of MethodToCall. The only thing I now for sure about the contents of returnedInfo is that it will implement IEnumerable.

int returnedInfoCount = (int)returnedInfo.GetType().InvokeMember("Count", InstancePropertyBindings, null, returnedInfo , null);

That works too. I can see the proper value being assigned to returnedInfoCount.

Now comes the kicker: I want to access the first entry in returnedInfo. I tried this
object myData = returnedInfo.GetType().InvokeMember("Item", InstanceMethodBindings, null, returnedInfo, new object[] {0});

No luck. The exception says method Item is not found.
returnedInfo.GetType().InvokeMember("MoveNext", InstanceMethodBindings, null, returnedInfo, null);
object myData = returnedInfo.GetType().InvokeMember("Current", InstanceMethodBindings, null, returnedInfo, null);

Also dies - "MoveNext" is not found.

Does anyone have any ideas of how I can get at the first entry in returnedInfo?

Many thanks if you are kind enough to look into this.
Even more if you have a suggestion/solution/idea/words of encouragement...

edit: small error in the example code

Clive Pottinger
Victoria, BC

modified on Wednesday, July 23, 2008 6:54 PM

AnswerRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 13:01
sitebuilderLuc Pattyn23-Jul-08 13:01 
GeneralRe: How to access an IEnumerable item using reflection Pin
Clive D. Pottinger23-Jul-08 13:53
Clive D. Pottinger23-Jul-08 13:53 
GeneralRe: How to access an IEnumerable item using reflection [modified] Pin
Luc Pattyn23-Jul-08 14:52
sitebuilderLuc Pattyn23-Jul-08 14:52 
GeneralRe: How to access an IEnumerable item using reflection Pin
Clive D. Pottinger23-Jul-08 15:44
Clive D. Pottinger23-Jul-08 15:44 
GeneralRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 15:51
sitebuilderLuc Pattyn23-Jul-08 15:51 
GeneralRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 16:13
sitebuilderLuc Pattyn23-Jul-08 16:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.