我了解 C# Specflow 中挂钩的实用性,但为什么 BeforeScenario / AfterScenario 和 BeforeFeature / AfterFeature 必须是静态的?
查看 SpecFlow 的源代码,它看起来不像 Hooks 是静态类:
public abstract class HookAttribute : Attribute
{
// [...]
internal HookAttribute(HookType bindingEvent, string[] tags)
{
// [...]
}
}
// [...]
public class BeforeScenarioAttribute : HookAttribute
{
public BeforeScenarioAttribute(params string[] tags) : base(HookType.BeforeScenario, tags) { }
}
// [...]
public class BeforeFeatureAttribute : HookAttribute
{
public BeforeFeatureAttribute(params string[] tags) : base(HookType.BeforeFeature, tags) { }
}
你有一个具体的例子来说明你的意思吗?