Cannot convert lambda expression to type 'object' because it is not a delegate type

前端 未结 5 1095
广开言路
广开言路 2020-12-18 17:25

I have a base class that has a bool property which looks like this:

public abstract class MyBaseClass
{
     public bool InProgress { get; protected set; }
}         


        
5条回答
  •  不思量自难忘°
    2020-12-18 18:09

    I ran into this problem while writing unit tests. I was attempting to mock the behavior of a database to return a new object from a repository instead of actually connecting to a database.

    Make sure your object has a usable constructor. You may not be able to successfully instantiate that object the way you want to. Ensure if you using a lambda to point to a constructor that the constructor can be called in the same way in a normal instantiation statement.

    i.e.

    return x => new FakeObject();
    

    say in the case of

    var fake = new FakeObject();
    

    would not work then the lambda will also fail so be careful.

提交回复
热议问题