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
used2couldAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Have you tried using Object?...
0
used2couldAuthor Commented:
Thanks Idle Mind,
I can't use Object because the actions applied to the passed in Type are specific to the Type being used.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
If they are specific to that Type then you kinda have to pass that type in!...  =\

Otherwise, you could create an Interface and declare it of that Type.  Then anything class that Implements that Interface can be passed into the method.

Another option would be to pass it all in as the generic Object type and attempt to get the "specific" parts out via Reflection.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

used2couldAuthor Commented:
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
0
gregoryyoungCommented:
You could use reflection ...

Get an instance of the open generic method Parse<> (generic method definition) in this case then use MakeGenericMethod http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.makegenericmethod.aspx on it to create a MethodInfo that is your call to make ... then invoke the call through your method info .... voila

There is an example of this process here http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.makegenericmethod.aspx

Cheers,

Greg
0
gregoryyoungCommented:
@used2could of course not generics are strongly typed at compile time.
0
used2couldAuthor Commented:
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!
0
used2couldAuthor Commented:
I'll be inspecting the member's details via reflection. That should do it. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.