我为我的一个对象覆盖了GetHashCode()
。我的代码将从本地数据库检索一个副本,并从第三方端点检索另一个副本。
我已经看完下面的代码,可以看到我在处理过程中有各自不同的哈希值,但是两个对象的总体哈希返回相同。
例如,当我获得对象的第三方版本时,而DB版本具有有效的GUID,则SubscriptionId默认为00000000-0000-0000-0000-000000000000
。发生了什么事?
public partial class ImportSubscriptionRatePlanCharge
{
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + SubscriptionId.GetSafeHashCode();
hash = hash * 23 + SubscriptionRatePlanId.GetSafeHashCode();
hash = hash * 23 + SubscriptionRatePlanChargeId.GetSafeHashCode();
hash = hash * 23 + OriginalChargeId.GetSafeHashCode();
hash = hash * 23 + ProductRatePlanChargeId.GetSafeHashCode();
hash = hash * 23 + Number.GetSafeHashCode();
hash = hash * 23 + Name.GetSafeHashCode();
hash = hash * 23 + Type.GetSafeHashCode();
hash = hash * 23 + Model.GetSafeHashCode();
hash = hash * 23 + Uom.GetSafeHashCode();
hash = hash * 23 + Version.GetSafeHashCode();
hash = hash * 23 + PricingSummary.GetSafeHashCode();
hash = hash * 23 + PriceChangeOption.GetSafeHashCode();
hash = hash * 23 + PriceIncreasePercentage.GetSafeHashCode();
hash = hash * 23 + Currency.GetSafeHashCode();
hash = hash * 23 + Price.GetSafeHashCode();
hash = hash * 23 + Tiers.GetSafeHashCode();
hash = hash * 23 + IncludedUnits.GetSafeHashCode();
hash = hash * 23 + OveragePrice.GetSafeHashCode();
hash = hash * 23 + DiscountPercentage.GetSafeHashCode();
hash = hash * 23 + DiscountAmount.GetSafeHashCode();
hash = hash * 23 + ApplyDiscountTo.GetSafeHashCode();
hash = hash * 23 + DiscountLevel.GetSafeHashCode();
hash = hash * 23 + DiscountClass.GetSafeHashCode();
hash = hash * 23 + BillingDay.GetSafeHashCode();
hash = hash * 23 + ListPriceBase.GetSafeHashCode();
hash = hash * 23 + BillingPeriod.GetSafeHashCode();
hash = hash * 23 + SpecificBillingPeriod.GetSafeHashCode();
hash = hash * 23 + BillingTiming.GetSafeHashCode();
hash = hash * 23 + BillingPeriodAlignment.GetSafeHashCode();
hash = hash * 23 + Quantity.GetSafeHashCode();
hash = hash * 23 + SmoothingModel.GetSafeHashCode();
hash = hash * 23 + NumberOfPeriods.GetSafeHashCode();
hash = hash * 23 + OverageCalculationOption.GetSafeHashCode();
hash = hash * 23 + OverageUnusedUnitsCreditOption.GetSafeHashCode();
hash = hash * 23 + UnusedUnitsCreditRates.GetSafeHashCode();
hash = hash * 23 + UsageRecordRatingOption.GetSafeHashCode();
hash = hash * 23 + Segment.GetSafeHashCode();
hash = hash * 23 + EffectiveStartDate.GetSafeHashCode();
hash = hash * 23 + EffectiveEndDate.GetSafeHashCode();
hash = hash * 23 + ProcessedThroughDate.GetSafeHashCode();
hash = hash * 23 + ChargedThroughDate.GetSafeHashCode();
hash = hash * 23 + Done.GetHashCode();
hash = hash * 23 + TriggerDate.GetSafeHashCode();
hash = hash * 23 + TriggerEvent.GetSafeHashCode();
hash = hash * 23 + EndDateCondition.GetSafeHashCode();
hash = hash * 23 + UpToPeriodsType.GetSafeHashCode();
hash = hash * 23 + UpToPeriods.GetSafeHashCode();
hash = hash * 23 + SpecificEndDate.GetSafeHashCode();
hash = hash * 23 + Mrr.GetSafeHashCode();
hash = hash * 23 + Dmrc.GetSafeHashCode();
hash = hash * 23 + Tcv.GetSafeHashCode();
hash = hash * 23 + Dtcv.GetSafeHashCode();
hash = hash * 23 + Description.GetSafeHashCode();
return hash;
}
}
public override bool Equals(object obj)
{
if (!(obj is ImportSubscriptionRatePlanCharge target)
|| this.SubscriptionId != target.SubscriptionId
|| this.SubscriptionRatePlanId != target.SubscriptionRatePlanId
|| this.SubscriptionRatePlanChargeId != target.SubscriptionRatePlanChargeId)
return false;
return this.OriginalChargeId == target.OriginalChargeId
&& this.ProductRatePlanChargeId == target.ProductRatePlanChargeId
&& this.Number == target.Number
&& this.Name == target.Name
&& this.Type == target.Type
&& this.Model == target.Model
&& this.Uom == target.Uom
&& this.Version == target.Version
&& this.PricingSummary == target.PricingSummary
&& this.PriceChangeOption == target.PriceChangeOption
&& this.PriceIncreasePercentage == target.PriceIncreasePercentage
&& this.Currency == target.Currency
&& this.Price == target.Price
&& this.Tiers == target.Tiers
&& this.IncludedUnits == target.IncludedUnits
&& this.OveragePrice == target.OveragePrice
&& this.DiscountPercentage == target.DiscountPercentage
&& this.DiscountAmount == target.DiscountAmount
&& this.ApplyDiscountTo == target.ApplyDiscountTo
&& this.DiscountLevel == target.DiscountLevel
&& this.DiscountClass == target.DiscountClass
&& this.BillingDay == target.BillingDay
&& this.ListPriceBase == target.ListPriceBase
&& this.BillingPeriod == target.BillingPeriod
&& this.SpecificBillingPeriod == target.SpecificBillingPeriod
&& this.BillingTiming == target.BillingTiming
&& this.BillingPeriodAlignment == target.BillingPeriodAlignment
&& this.Quantity == target.Quantity
&& this.SmoothingModel == target.SmoothingModel
&& this.NumberOfPeriods == target.NumberOfPeriods
&& this.OverageCalculationOption == target.OverageCalculationOption
&& this.OverageUnusedUnitsCreditOption == target.OverageUnusedUnitsCreditOption
&& this.UnusedUnitsCreditRates == target.UnusedUnitsCreditRates
&& this.UsageRecordRatingOption == target.UsageRecordRatingOption
&& this.Segment == target.Segment
&& this.EffectiveStartDate == target.EffectiveStartDate
&& this.EffectiveEndDate == target.EffectiveEndDate
&& this.ProcessedThroughDate == target.ProcessedThroughDate
&& this.ChargedThroughDate == target.ChargedThroughDate
&& this.Done == target.Done
&& this.TriggerDate == target.TriggerDate
&& this.TriggerEvent == target.TriggerEvent
&& this.EndDateCondition == target.EndDateCondition
&& this.Name == target.UpToPeriodsType
&& this.UpToPeriods == target.UpToPeriods
&& this.SpecificEndDate == target.SpecificEndDate
&& this.Mrr == target.Mrr
&& this.Mrr == target.Dmrc
&& this.Tcv == target.Tcv
&& this.Dtcv == target.Dtcv
&& this.Description == target.Description;
}
}