mardi 16 juin 2020

Checking Enums Values - alternative to a switch case with 30 cases?

I need to find if all conditions fit a certain criteria.

public class OfferServiceConditionDto
{

    public long Id { get; set; }

    public Parameter Parameter { get; set; }

    public Enums.Condition Condition { get; set; }

    public double? Value { get; set; }

    [JsonIgnore]
    public long? OfferSubServiceId { get; set; }
}

Parameters has 5 cases:

public enum Parameter : int
{
    Length,
    Width
    Height,
    Area,
    Volume
}

Condition has 6 cases:

public enum Condition : int
{
    LessThan,
    LessThanOrEqualTo,
    Equals,
    GreaterThan,
    GreaterThanOrEqualTo,
    DoesNotEqual
}

IN my function I am given an element width height and length and I need to check against OfferServiceConditionDto conditions, paremeters and value.

So far I am only thinking switch cases or ifs but that's a whooping 30 checks.

Any better alternative for this?

Aucun commentaire:

Enregistrer un commentaire