gpt4 book ai didi

c# - 在 MSpec 中,为什么所有被测字段都必须是静态的?

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:41 26 4
gpt4 key购买 nike

是什么让 MSpec 只需要静态字段?比如这里的代码会报错

public class When_not_enabled
{
private static ActionExecutingContext filterContext;

// On purpose I've made subject non static
private CompleteOrderGuardFilter subject;

Establish context = () =>
{
// Here I get cannot access non static field in static context
subject = new CompleteOrderGuardFilter(null, false);
filterContext = new ActionExecutingContext();
};
}

错误:

cannot access non static field in static context

最佳答案

MSpec 不实例化上下文类,而是直接调用 Establish/Because/It/Cleanup 委托(delegate)。因此,没有创建状态(类实例),您需要在委托(delegate)之间传递的所有信息都全局可用,例如。 G。 静态

关于c# - 在 MSpec 中,为什么所有被测字段都必须是静态的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28323185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com