问题
"An object reference is required for the non-static field" I have a static member which cannot be an instance member. This static member uses an instance of an object that is initialized in the constructor of the class through dependency injection, so it cannot be static. How could I solve this error?
public class My
{
private readonly Fixture _fixture;
public MyClass(Fixture fixture)
{
_fixture = fixture;
}
public static IEnumerable<object[]> TestCases()
{
yield return new object[] { Urls.BuildUrl(_fixture.WebAppUrl)};
}
[Theory]
[MemberData(nameof(TestCases))]
...
public static class Urls
{
public static string BuildUrl(string url)
{
...
The error is thrown here:
yield return new object[] { Urls.**BuildUrl**(_fixture.WebAppUrl)};
来源:https://stackoverflow.com/questions/60605398/static-member-error-with-instance-member-xunit