Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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
.net 结果lambda表达式执行;ToList();这种方法与以前不同_.net_Reflection_Lambda - Fatal编程技术网

.net 结果lambda表达式执行;ToList();这种方法与以前不同

.net 结果lambda表达式执行;ToList();这种方法与以前不同,.net,reflection,lambda,.net,Reflection,Lambda,这是我的密码: 项目1: public interface IComponent{} public class ComponentTest:IComponent{} public class Bootstraper { public virtual IEnumerable<IComponent> GetComponents() { return Directory.GetFiles(AppDomain.CurrentDomain.BaseDirector

这是我的密码:

项目1:

public interface IComponent{}

public class ComponentTest:IComponent{}

public class Bootstraper
{
   public virtual IEnumerable<IComponent> GetComponents()
   {
       return Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
       .Select(Assembly.LoadFile).SelectMany(m => m.GetTypes()).Select(m => m.GetTypeInfo())
       .Where(m => !m.IsAbstract && !m.IsInterface 
                   && typeof(IComponent).IsAssignableFrom(m)).ToList()
       .Select(Activator.CreateInstance).Cast<IPlatformComponent>();
   }
}
公共接口IComponent{}
公共类ComponentTest:IComponent{}
公共类引导器
{
公共虚拟IEnumerable GetComponents()
{
返回目录.GetFiles(AppDomain.CurrentDomain.BaseDirectory,“*.dll”)
.Select(Assembly.LoadFile).SelectMany(m=>m.GetTypes()).Select(m=>m.GetTypeInfo())
.其中(m=>!m.isastract&!m.IsInterface
&&typeof(IComponent).IsAssignableFrom(m)).ToList()
.Select(Activator.CreateInstance.Cast();
}
}
项目单元测试:

[TestMethod]
public void GetComponenentsIsSuccess()
{
    Bootstraper testObj=new Bootstraper();

    IEnumerable<IComponent> ienumerable = testObj.GetComponents();
    Assert.IsTrue(ienumerable.Any(m=>m.GetType()==typeof(ComponenentTest)));
}
[TestMethod]
public void GetComponenentsIsSuccess()
{
Bootstraper testObj=new Bootstraper();
IEnumerable IEnumerable=testObj.GetComponents();
Assert.IsTrue(ienumerable.Any(m=>m.GetType()==typeof(ComponenentTest));
}
执行单元测试时,它找不到组件测试

我有两个问题:

1.在VS Debugger视图中,代码
其中(m=>!m.isastract&&!m.IsInterface&&typeof(IComponent).IsAssignableFrom(m))
可以获取类型
组件测试
,但在执行
ToList()
方法时,该类型被分发

2.code为
typeof(IComoponent)
时,类型
ComponentTest
是分散的,但我使用
typeof(object)
代替,在执行“ToList()”之后,
ComponentTest
仍在集合中

对于ToList(),添加命名空间
使用System.Linq

命名空间已添加运行时为.net core 2.0