Click here to Skip to main content
14,486,515 members
   

C#

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

I continued looking for a way without calling GetEnumerator explicitly, and this
now works fine for me:

public override void Run(int arg) {
	Type type=Type.GetType("LPExplorer.CPTest_Enumerator+MyList");
	log("type="+type);
	IEnumerable aList=System.Activator.CreateInstance(type) as IEnumerable;
	log("aList="+aList);
	if (aList!=null) foreach (string s in aList) log(s);
}
 
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(); }
}
</string></string>


So once the object (aList) exists I don't need reflection to enumerate, provided
I know (or the code somehow finds out) what the type of the items is.

As I mentioned before, aList must be an object, i.e. an instance; it would not work
on static classes.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Voting for dummies? No thanks. Dead | X|


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 
AnswerRe: Windows Service - Access is denied. Pin
mark_w_23-Jul-08 5:46
Membermark_w_23-Jul-08 5:46 
GeneralRe: Windows Service - Access is denied. Pin
dataminers23-Jul-08 8:22
Memberdataminers23-Jul-08 8:22 
AnswerRe: Windows Service - Access is denied. Pin
Frank Horn23-Jul-08 6:52
MemberFrank Horn23-Jul-08 6:52 
AnswerRe: Windows Service - Access is denied. Pin
dataminers24-Jul-08 7:22
Memberdataminers24-Jul-08 7:22 
Questionuse the loudspeakers with C# Pin
amityo23-Jul-08 5:08
Memberamityo23-Jul-08 5:08 

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.