此代码中反射的输出类型是什么

我有以下方法:


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;

    }

}

列表的类型是什么?


如果我做:


foreach (var l in L) { ... }

它可以找到并且我可以检查类型,但是我正在使用的开发环境 (Rider) 不会提供类型


翻翻过去那场雪
浏览 60回答 1
1回答

喵喔喔

它是一个具有单一属性的匿名对象IEnumerable<Type> Types;所以,使用A.ToList()给你一个匿名对象的列表,你不能返回。我认为select new { Type = Types };你想使用而不是使用select Types;所以:public static List<Type> FindType<T>(){&nbsp; &nbsp; var types =&nbsp; &nbsp; &nbsp; &nbsp; from ssembly in AppDomain.CurrentDomain.GetAssemblies().AsParallel()&nbsp; &nbsp; &nbsp; &nbsp; from type in ssembly.GetTypes()&nbsp; &nbsp; &nbsp; &nbsp; let attributes = type.GetCustomAttributes(typeof(T), true)&nbsp; &nbsp; &nbsp; &nbsp; where attributes?.Length > 0&nbsp; &nbsp; &nbsp; &nbsp; select type;&nbsp; &nbsp; return types.ToList();}
打开App,查看更多内容
随时随地看视频慕课网APP