我想将委托约束为某个类型的成员。例如......
class Foo {
public virtual void Bar() {}
}
class Baz : Foo {
public override void Bar() {
this.BarAndMore(base.Bar);
}
}
delegate void FooMemberDelegate(); // Can I restrict this so `FooMemberDelegate`s can only be assigned to members of Foo
static class Extensions {
public static void BarAndMore(this Foo foo, FooMemberDelegate fooMemberDelegate) {
// Other stuff
fooMemberDelegate();
// More stuff
}
}
编辑:似乎是How can I constrain a method that takes an Action<T> to only allow delegates from a specific class
的副本