I'm trying to port an existing C# class (a generic factory) that uses reflection, but I can't get this piece of code to compile:
Type[] types = Assembly.GetAssembly(typeof(TProduct)).GetTypes();
foreach (Type type in types)
{
if (!typeof(TProduct).IsAssignableFrom(type) || type == typeof(TProduct))
...
I tried looking at the Reflection in the .NET Framework for Windows Metro Style Apps and Assembly Class, where I found an example that didn't compile because of the "using System.Security.Permissions".
Just like the first page you linked to says, you need to use
TypeInfo
instead ofType
. There are also other changes, for example,Assembly
has aDefinedTypes
property instead ofGetTypes()
method. The modified code could look like this: