Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
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 
Thanks Luc, but it won't work. However, building on your example may make it a little simpler to illustrate my problem:

public void myGetData(string myEnumerableTypeName)
{
  object myEnumerableType = (code that returns myEnumerableType as an object)

  foreach(MyType item in myEnumerableType) 
  {
    item.SomeMethod();
  }
}

Note that I have myEnumerableType, but only as an instance of an object, and objects don't implement IEnumerable.

If I could cast myEnumerableType as an IEnumerable object, then I could write
foreach(MyType item in (IEnumerable)myEnumerableType)
But, IEnumerable is an interface, so casting is not allowed.

If I could dynamically implement IEnumerable, perhaps
foreach(MyType item in myEnumerableType:IEnumerable)
but the Gods of Syntax threw a bolt of lighting at me for just suggesting it.

I can get the original type of myEnumerableType
Type origType = myEnumberableType.GetType();
Again, if I could dynamically cast then I could do
foreach(MyType item in ((Type)origType)myEnumerableType)
but that time the GoS punished me by replacing all my screensavers with jpegs of Ugly Betty.

Clive Pottinger
Victoria, BC

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 
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 
GeneralRe: dropdownlist data fetch Pin
nelsonpaixao23-Jul-08 14:43
nelsonpaixao23-Jul-08 14:43 
GeneralRe: dropdownlist data fetch Pin
scottichrosaviakosmos23-Jul-08 17:23
scottichrosaviakosmos23-Jul-08 17:23 
AnswerRe: dropdownlist data fetch [modified] Pin
nelsonpaixao24-Jul-08 13:39
nelsonpaixao24-Jul-08 13:39 
QuestionProblem booking timeslots within a range of dates Pin
Twyce23-Jul-08 7:18
Twyce23-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
jchalfant23-Jul-08 7:13 
AnswerRe: Wizard Control Suggestions Pin
Pete O'Hanlon23-Jul-08 9:45
mvePete O'Hanlon23-Jul-08 9:45 
GeneralRe: Wizard Control Suggestions Pin
jchalfant23-Jul-08 11:15
jchalfant23-Jul-08 11:15 
GeneralRe: Wizard Control Suggestions Pin
Pete O'Hanlon24-Jul-08 10:07
mvePete O'Hanlon24-Jul-08 10:07 
QuestionXmlSchemaProvider XSD import problem Pin
Guinness4Strength23-Jul-08 5:52
Guinness4Strength23-Jul-08 5:52 
QuestionWindows Service - Access is denied. Pin
dataminers23-Jul-08 5:23
dataminers23-Jul-08 5:23 
AnswerRe: Windows Service - Access is denied. Pin
mark_w_23-Jul-08 5:46
mark_w_23-Jul-08 5:46 
GeneralRe: Windows Service - Access is denied. Pin
dataminers23-Jul-08 8:22
dataminers23-Jul-08 8:22 
AnswerRe: Windows Service - Access is denied. Pin
Frank Horn23-Jul-08 6:52
Frank Horn23-Jul-08 6:52 
AnswerRe: Windows Service - Access is denied. Pin
dataminers24-Jul-08 7:22
dataminers24-Jul-08 7:22 

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.