C# 在这段代码中,反射的输出类型是什么
我有以下方法:C# 在这段代码中,反射的输出类型是什么,c#,reflection,C#,Reflection,我有以下方法: public static class ReflectionHelper { public static List<?> FindType<T>() { var A = from Assemblies in AppDomain.CurrentDomain.GetAssemblies().AsParallel() from Types in Assemblies.GetTypes
public static class ReflectionHelper
{
public static List<?> FindType<T>()
{
var A =
from Assemblies in AppDomain.CurrentDomain.GetAssemblies().AsParallel()
from Types in Assemblies.GetTypes()
let Attributes = Types.GetCustomAttributes(typeof(T), true)
where Attributes?.Length > 0
select new { Type = Types };
var L = A.ToList();
return L;
}
}
它可以查找,我可以遍历类型,但我使用的开发环境(Rider)不会提供类型。它是一个具有单个属性的匿名对象
IEnumerable<Type> Types;
它是匿名类型,因此不能直接将该类型用作方法返回类型。在您的特定情况下,您可以将其更改为:select Types,然后泛型类型将是type(除非您将其展平,否则它实际上将是List>)。我可以得到关于下一票的解释吗?“SelectMany”没有编译(我已经完成了“select Types”更改)。
IEnumerable<Type> Types;
public static List<Type> FindType<T>()
{
var types =
from ssembly in AppDomain.CurrentDomain.GetAssemblies().AsParallel()
from type in ssembly.GetTypes()
let attributes = type.GetCustomAttributes(typeof(T), true)
where attributes?.Length > 0
select type;
return types.ToList();
}