是否可以将委托约束为类型的成员?

时间:2014-11-10 19:56:08

标签: c# delegates

我想将委托约束为某个类型的成员。例如......

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

的副本

0 个答案:

没有答案