mercredi 24 octobre 2018

C# Optimize Equateable method

I extended equals and gethashcode to compare two objects. It works fine, however, this is an enterprise level app and I need to get rid of extra payload. The objects only compare boolean properties. No strings, integers nothing but boolean. Does anyone have a suggestion to improve this?

public partial class OrderSpecPropertyOptions : IPropertyOptionWithIdentifier, IEquatable<OrderSpecPropertyOptions>
{
    public override bool Equals(object value)
    {
        if (!(value is OrderSpecPropertyOptions options))
            return false;

        return Equals(options);
    }

    public bool Equals(OrderSpecPropertyOptions options)
    {
        return options.GetHashCode() == GetHashCode();
    }

    public override int GetHashCode()
    {
        return ToString().GetHashCode();
    }

    public override string ToString()
    {
        return $"{Identifier}{AdditionalServiceTime}{BeginDate}{CoordinateOverride}{DeliveryAdditionalServiceTime}" +
               $"{DeliveryCoordinateOverride}{DeliveryLocationEntityKey}{DeliveryOpenCloseOverrides}" +
               $"{DeliveryQuantities}{DeliveryServiceWindowOverrides}{EndDate}{LineItems}{ManagedByUserEntityKey}{OrderClassEntityKey}" +
               $"{PickupLocationEntityKey}{PickupQuantities}{Quantities}{Selector}" +
               $"{ServiceLocationEntityKey}{SessionEntityKey}{SpecialInstructions}{TakenBy}{LineItemsOptions}";
    }
}





Aucun commentaire:

Enregistrer un commentaire