Skip to content

Add DateTime and numeric constructors to filters #119

@JanLenoch

Description

@JanLenoch

Motivation

When using filters, the developer always specifies the element or attribute path (the predicate) and a value to filter by. The value has to be formatted specifically in order for the SDK to understand it.

Design guidelines

  • Create a generic Filter class that will accept T instead of string for the value parameter in its constructor
  • The Filter class will store Ts instead of strings in the Values property
  • Add DateTime and decimal constructors to all applicable filters.
  • The constructors will utilize the updated constructor of Filter that accepts objects as values
  • The GetQueryStringParameter() method of Filter will use pattern matching to distinguish between various types and will behave according to the specification:
    • format DateTime values to ISO-8601
    • format numeric types (int, float...) to "##########.##########"
    • treat all other types as strings and perform the current behavior

Example

    public string GetQueryStringParameter()
    {
        IEnumerable<string> values = Values switch
        {
            DateTime[] dates => values = dates.Select(d => d.ToString("o")),
            int[] numbers => numbers.Select(n => n.ToString()),
            _ => Values.Select(v => v.ToString())
        };

        var op = Uri.EscapeDataString(Operator ?? string.Empty);
        var element = Uri.EscapeDataString(ElementOrAttributePath);
        var escapedValues = string.Join(SEPARATOR, values.Select(Uri.EscapeDataString));
        return string.Format($"{element}{op}={escapedValues}");
    }

References

Pattern matching:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions