我有一个类,其中每个方法都以相同的方式开始:
internal class Foo {
public void Bar() {
if (!FooIsEnabled) return;
//...
}
public void Baz() {
if (!FooIsEnabled) return;
//...
}
public void Bat() {
if (!FooIsEnabled) return;
//...
}
}
有没有一种很好的方法来要求(希望不是每次都写)类中每个公共(public)方法的 FooIsEnabled
部分?
我检查 Is there an elegant way to make every method in a class start with a certain block of code? ,但是这个问题是针对 Java 的,它的答案是使用 Java 库。
最佳答案
关于c# - 有没有一种优雅的方法可以让类中的每个方法都以 C# 中的某个代码块开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31153253/