查看是否 Ninject 激活上下文绑定到类型

See if Ninject Activation Context bound to Type

我正在尝试对使用 Ninject 的类型有选择地使用拦截。如果一个实现实现了一个特定的接口,我想拦截它。我如何检查 Ninject 激活上下文以查看其目标是否实现了接口?

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var kernal = new StandardKernel();
        kernal.Bind<IFoo>().To<Foo>();

        kernal.Intercept(x =>
        {
            if (x is an IGetIntercepted)
            {
                return true;
            }
            return false;
        });
    }

    public interface IGetIntercepted
    { }

    public interface IFoo
    { }

    public class Foo : IFoo, IGetIntercepted
    { }
}

我忽略了计划 属性,这似乎有效:

if (x.Plan.Type.GetInterface(typeof(IGetIntercepted).FullName) != null)
{
    return true;
}