By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,667 Members | 1,697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,667 IT Pros & Developers. It's quick & easy.

Dynamically creating generic collections : Collection<T> using .Net Framework 2

P: n/a
Can anyone tell me if it is possible to dynamically create generic
collections?

simply put I want to be able to something like this :

public object test(SomeBaseClass param1)
{
if (param1.prop1 == "blah")
{
//logic to determine the type
return Collection<a class derived from SomeBaseClass>
}
else
{
//logic to determine the type
return Collection<a different class derived from SomeBaseClass>
}
}

where the type of param1 is a superclass, but the passed parameter is
derived from the superclass.

I basically need to be able to make this generic so I can dynamically create
the strongly typed collection from a type determined at runtime.

Thanks
Andy
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I basically need to be able to make this generic so I can dynamically create
the strongly typed collection from a type determined at runtime.


You can do this with Reflection (System.Type.BindGenericParameters).


Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.