Click here to Skip to main content
15,892,674 members
Home / Discussions / C#
   

C#

 
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 
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 
Hi Clive,

First a few minor corrections to your message:

cpotting wrote:
but only as an instance of an object, and objects don't implement IEnumerable.


- objects are instances of classes
- classes can implement an interface
- objects can be cast to an interface, the compiler will accept, the run-time check
may fail; in your case, it cannot prove the object IS an instance of an IEnumerable
class, so it refuses to cast.

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<string> list=new List<string>();
 
	public MyList() {
		list.Add("aaa");
		list.Add("bbb");
		list.Add("ccc");
	}
 
	public IEnumerator GetEnumerator() { return list.GetEnumerator(); } // LINE WAS MISSING!
}
</string></string>


Hope this helps.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Voting for dummies? No thanks. Dead | X|


modified on Wednesday, July 23, 2008 8:58 PM

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 
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
Clive 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
scottichrosaviakosmos23-Jul-08 8:02 

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.