Porting C # reflection code to Metro-Ui
I am trying to hook up an existing C # class (generic factory) that uses reflection, but I cannot compile this piece of code:
Type[] types = Assembly.GetAssembly(typeof(TProduct)).GetTypes();
foreach (Type type in types)
{
if (!typeof(TProduct).IsAssignableFrom(type) || type == typeof(TProduct))
...
I tried to take a look at Reflection in the .NET Framework for Windows Metro Style Apps and Assembly Class where I found an example that didn't compile due to "using System.Security.Permissions".
source to share
Like the first page you link to, you should use TypeInfo
instead Type
. There are other changes, such as Assembly
has a property DefinedTypes
instead of a method GetTypes()
. The modified code might look like this:
var tProductType = typeof(TProduct).GetTypeInfo();
var types = tProductType.Assembly.DefinedTypes; // or .ExportedTypes
foreach (var type in types)
{
if (!tProductType.IsAssignableFrom(type) || type == tProductType)
{ }
}
source to share