我目前正在尝试将 Xamarin.iOS 应用程序库转换为 PCL(配置文件 78)。我有这段代码无法编译:
public static void RegisterAllCommandHandlers(IEnumerable<Assembly> assemblies) {
// Get all types that are concrete classes which implement ICommandHandler
var commandHandlerOpenGenericType = typeof(ICommandHandler<>);
var types = new List<Type>();
foreach (var assembly in assemblies) {
types.AddRange(assembly.GetTypes()
.Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == commandHandlerOpenGenericType)));
}
}
Here is an image of the compiler errors:
如何使用新的反射 API 做同样的事情?
这是由于类型/类型信息分离造成的。看改进反射 API http://blogs.msdn.com/b/dotnet/archive/2012/08/28/evolving-the-reflection-api.aspx.
试试这个代码:
assembly.DefinedTypes
.Where(x => x.IsClass && !x.IsAbstract && x.ImplementedInterfaces
.Any(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == commandHandlerOpenGenericType))
.Select(x => x.AsType())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)