Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从程序集c获取类型时,如何排除集合#_C#_Reflection - Fatal编程技术网

C# 从程序集c获取类型时,如何排除集合#

C# 从程序集c获取类型时,如何排除集合#,c#,reflection,C#,Reflection,我有以下方法: public static Type[] GetAllClasses(this Assembly assembly) { var types= assembly.GetExportedTypes().Where(x=>x.IsClass).OrderBy(x=>x.Name).ToArray(); return types; } 我想排除所有属于集合的类型。我如何才能做到这一点 调试时,我可以看到集合有一个基类型“List'1

我有以下方法:

 public static Type[] GetAllClasses(this Assembly assembly)
 {
        var types= assembly.GetExportedTypes().Where(x=>x.IsClass).OrderBy(x=>x.Name).ToArray();

        return types;
 }
我想排除所有属于集合的类型。我如何才能做到这一点

调试时,我可以看到集合有一个基类型“List'1”。如何捕获并排除这些基类型


非常感谢

这可能有用

var types= assembly.GetExportedTypes()
.Where(x=>x.IsClass && x.GetInterface("IEnumerable")==null)
.OrderBy(x=>x.Name).ToArray();

(如果要排除这些接口,请使用更具体的集合接口-IList或ICollection)

刚刚进行了修改。没有看到您想要排除集合。