【问题标题】:Overridding GetHashCode and Equals in Castle Dynamic Proxy 2.1 IModelInterceptorsSelector在 Castle Dynamicproxy 2.1 IModelInterceptorsSelector 中覆盖 GetHashCode 和 Equals
【发布时间】:2010-07-06 15:53:31
【问题描述】:

我已经阅读了这篇文章,以便在使用 Castle Dynamic Proxy 时使用拦截器选择器时获得缓存和推送性能,我需要覆盖 GetType()、GetHashCode() 和 Equals()

从执行的角度来看,我在哪里可以找到实施的示例或最好的实施方式?

【问题讨论】:

    标签: castle-windsor castle castle-dynamicproxy


    【解决方案1】:

    你不能覆盖 GetType,它不是虚拟的。

    对于其余的,使用与任何其他类型相同的技术。 我通常使我的选择器无状态,并将方法实现为this.GetType().GetHashCode()This.GetType() == other.GetType()

    【讨论】:

    • 对于无状态选择器,像这样简单: public override bool Equals(object obj) { return this.GetType() == obj.GetType(); } 公共覆盖 int GetHashCode() { return this.GetType().GetHashCode(); }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 2014-01-03
    • 1970-01-01
    相关资源
    最近更新 更多