mercredi 29 juillet 2020

How to replace IF statements for dictionary? (C#, Linq)

I have this equality comparer of a SampleObject:

    public bool Equals(SampleObject x, SampleObject y)
    {
        if (x == null)
        {
            return y == null;
        }

        if (y == null)
        {
            return false;
        }

        if (!string.Equals(x.SomeId, y.SomeId))
        {
            return false;
        }

        if (x.EventsList == null)
        {
            return y.EventsList == null;
        }

        if (y.EventsList == null)
        {
            return false;
        }

        return x.EventsList.OrderBy(e => e)
            .SequenceEqual(y.EventsList.OrderBy(e => e));
    }

What I would like to know is if there is a way to replace all those IF clauses for a dictionary?

Aucun commentaire:

Enregistrer un commentaire