Click here to Skip to main content
14,493,463 members
   

C#

 
AnswerRe: Copy Dictionay Object To Other [modified] Pin
Elroy Dsilva23-Jul-08 17:10
MemberElroy Dsilva23-Jul-08 17:10 
AnswerRe: Copy Dictionay Object To Other Pin
Elroy Dsilva23-Jul-08 17:37
MemberElroy 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
MemberN 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
MemberClive D. Pottinger23-Jul-08 12:39 
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
MemberClive 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
MemberClive D. Pottinger23-Jul-08 15:44 
Luc Pattyn wrote:
Now IMO this is the right plan of attack:

- get your object;
- use reflection to execute its GetEnumerator() method and store the result as a
new object (of type IEnumerator), say myEnumerator.
- on myEnumerator, call methods Reset(), MoveNext() and the property Current
as you see fit; no need for reflection here.

This is code I have running:


public override void Run(int arg) {
MyList list=new MyList();
IEnumerator ienumer= typeof(MyList).InvokeMember("GetEnumerator", InstanceMethodBindings, null, list, null)
as IEnumerator;
log("ienumer="+ienumer);
while (ienumer.MoveNext()) log((string)ienumer.Current);
}

public class MyList : IEnumerable {
private List list=new List();

public MyList() {
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
}

public IEnumerator GetEnumerator() { return list.GetEnumerator(); } // LINE WAS MISSING!
}


Thanks again, Luc.

I did not see this and your next post until after I posted my answer. But it is enlightening to see your approach anyway.

There would be two problems with implementing the solution you give above:
1) It requires the me to declare ienumer as type IEnumerable. I do not have this ability (I think it is because we are still using .NET 2.0 here).
2) the line
while (ienumer.MoveNext()) log((string)ienumer.Current);
requires that the type returned by ienumer.Current be hardcoded as string. But I cannot hardcode the type, because, in my situation, I may be working on MyList, or MyIntList, or MySomeOtherClassList...

None the less, your suggestions got me past both issues and my code is working wonderfully. I know I would still be floundering about if it wasn't for guru's like you and the rest of the TheCodeProject folks.

Cheers!

Clive Pottinger
Victoria, BC

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 
GeneralRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 15:16
sitebuilderLuc Pattyn23-Jul-08 15:16 
AnswerRe: How to access an IEnumerable item using reflection Pin
Clive D. Pottinger23-Jul-08 14:43
MemberClive D. Pottinger23-Jul-08 14:43 
GeneralWithout explicit GetEnumerator Pin
Luc Pattyn24-Jul-08 2:19
sitebuilderLuc Pattyn24-Jul-08 2:19 
Questiondropdownlist data fetch Pin
scottichrosaviakosmos23-Jul-08 8:02
Memberscottichrosaviakosmos23-Jul-08 8:02 
GeneralRe: dropdownlist data fetch Pin
nelsonpaixao23-Jul-08 14:43
Membernelsonpaixao23-Jul-08 14:43 
GeneralRe: dropdownlist data fetch Pin
scottichrosaviakosmos23-Jul-08 17:23
Memberscottichrosaviakosmos23-Jul-08 17:23 
AnswerRe: dropdownlist data fetch [modified] Pin
nelsonpaixao24-Jul-08 13:39
Membernelsonpaixao24-Jul-08 13:39 
QuestionProblem booking timeslots within a range of dates Pin
Twyce23-Jul-08 7:18
MemberTwyce23-Jul-08 7:18 
AnswerRe: Problem booking timeslots within a range of dates Pin
Luc Pattyn23-Jul-08 8:01
sitebuilderLuc Pattyn23-Jul-08 8:01 
QuestionWizard Control Suggestions Pin
jchalfant23-Jul-08 7:13
Memberjchalfant23-Jul-08 7:13 
AnswerRe: Wizard Control Suggestions Pin
Pete O'Hanlon23-Jul-08 9:45
subeditorPete O'Hanlon23-Jul-08 9:45 
GeneralRe: Wizard Control Suggestions Pin
jchalfant23-Jul-08 11:15
Memberjchalfant23-Jul-08 11:15 
GeneralRe: Wizard Control Suggestions Pin
Pete O'Hanlon24-Jul-08 10:07
subeditorPete O'Hanlon24-Jul-08 10:07 
QuestionXmlSchemaProvider XSD import problem Pin
Guinness4Strength23-Jul-08 5:52
MemberGuinness4Strength23-Jul-08 5:52 
QuestionWindows Service - Access is denied. Pin
dataminers23-Jul-08 5:23
Memberdataminers23-Jul-08 5:23 

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.