什么"陷阱"我应该注意何时使用Resharper生成IEquatable接口?

时间:2014-10-01 22:22:31

标签: c# resharper iequatable

我使用Resharper生成了以下代码。我想知道它是否好,或者是否有问题我需要修理/注意。

我想知道m_customTRP的比较。 m_customTRP是一个IList,TimeRfPower也实现了IEquatable。以下一行也是如此......

Equals(m_customTRP, other.m_customTRP)

...使用TimeRfPower类的Equals()方法比较每个TimeRfPower?

    //*********************************************************************
    // IEquatable Interface - implemented with Resharper
    //*********************************************************************
    protected bool Equals(Waveform other)
    {
        return base.Equals(other) && m_sweepSpan.Equals(other.m_sweepSpan)
            && m_sweepRate.Equals(other.m_sweepRate)
            && m_bandwidth.Equals(other.m_bandwidth)
            && m_centerFrequency.Equals(other.m_centerFrequency)
            && m_waveformType == other.m_waveformType
            && m_dutyCycle.Equals(other.m_dutyCycle)
            && m_pulsePeriod.Equals(other.m_pulsePeriod)
            && m_modulationFrequency.Equals(other.m_modulationFrequency)
            && m_relativePowerIncrement.Equals(other.m_relativePowerIncrement)
            && m_relativeTimeIncrement.Equals(other.m_relativeTimeIncrement)
            && m_endRelativePower.Equals(other.m_endRelativePower)
            && m_timeRFOn.Equals(other.m_timeRFOn)
            && m_timeRFOff.Equals(other.m_timeRFOff)
            && m_powerReferenceType == other.m_powerReferenceType
            && Equals(m_customTRP, other.m_customTRP);
    }

    //*********************************************************************
    // IEquatable Interface - implemented with Resharper
    //*********************************************************************
    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != this.GetType()) return false;
        return Equals((Waveform)obj);
    }

    //*********************************************************************
    // IEquatable Interface - implemented with Resharper
    //*********************************************************************
    public override int GetHashCode()
    {
        unchecked
        {
            int hashCode = base.GetHashCode();
            hashCode = (hashCode * 397) ^ m_sweepSpan.GetHashCode();
            hashCode = (hashCode * 397) ^ m_sweepRate.GetHashCode();
            hashCode = (hashCode * 397) ^ m_bandwidth.GetHashCode();
            hashCode = (hashCode * 397) ^ m_centerFrequency.GetHashCode();
            hashCode = (hashCode * 397) ^ (int)m_waveformType;
            hashCode = (hashCode * 397) ^ m_dutyCycle.GetHashCode();
            hashCode = (hashCode * 397) ^ m_pulsePeriod.GetHashCode();
            hashCode = (hashCode * 397) ^ m_modulationFrequency.GetHashCode();
            hashCode = (hashCode * 397) ^ m_relativePowerIncrement.GetHashCode();
            hashCode = (hashCode * 397) ^ m_relativeTimeIncrement.GetHashCode();
            hashCode = (hashCode * 397) ^ m_endRelativePower.GetHashCode();
            hashCode = (hashCode * 397) ^ m_timeRFOn.GetHashCode();
            hashCode = (hashCode * 397) ^ m_timeRFOff.GetHashCode();
            hashCode = (hashCode * 397) ^ (int)m_powerReferenceType;
            hashCode = (hashCode * 397) ^ (m_customTRP != null ? m_customTRP.GetHashCode() : 0);

            return hashCode;
        }
    }

0 个答案:

没有答案