Link to home
Start Free TrialLog in
Avatar of used2could
used2could

asked on

List<myObject.GetType()> lstStuff Concept - Please Help

I am trying to do something like List<String> lstStuff without having to use the keyword "String". The objects that will go through this are dynamic and i can't reference it's type by name. I've tried things such as List<myObject.GetType()> or List<typeof(myObject)> but that give a compiler error. Are there any ways to pass the generic type without using the actual object's type name? Thanks. This is extremly urgant. i'm trying to implement a fix for a system that can only be brought down for a few hours.
Thanks.

Oh, as a side note the actual method i am trying this on isn't "List". I am using "List" as a popular example. It's really a custom method. Parse<T>(T objectToParse)

Thank you so much!

~B
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Have you tried using Object?...
Avatar of used2could
used2could

ASKER

Thanks Idle Mind,
I can't use Object because the actions applied to the passed in Type are specific to the Type being used.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There are too many different types that could be passed in. I'm going to have to use objects and reflection. I didn't want to go that route but oh well. Just for the record, there is no way to use List<GetType()> for generics?

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys!! i started re-writing it to accommodate objects and allow the method using generics to still access them via overloading to keep other things from breaking. Thanks for the clarifications!
I'll be inspecting the member's details via reflection. That should do it. Thanks!