Creating a generic filter system to pass into an API request
Am I on the right track here?


I think you are. Here's how you can use a few tricks to make it even shorter.



Instead of the interface you can implement what is common in an abstract class.

public abstract class Filter
{
    public virtual string Name =&gt; Regex.Replace(GetType().Name, $"{nameof(Filter)}$", string.Empty);
    public static implicit operator string(Filter filter) =&gt; filter.ToString();
}


This means the base class will get the name of the filter from its type and it'll be able to implicitly cast it into a string by calling ToString. Now everything the derived class needs to do is to implement its own ToString:

public class CreatedAfterFilter : Filter
{
    private DateTime _value;

    public CreatedAfterFilter(DateTime value)
    {
        _value = value;
    }

    public override string ToString()
    {
        return _value.ToString("yyyy-MM-ddTHH:mm:ss+00:00");
    }    
}


So later in the loop you can just do this:

foreach (var filter in filters)
{
   getParams.Add(new KeyValuePair&lt;string, string&gt;(filter.Name, filter));
}




If you make the Name property virtual you can override it in a derived class if the name of the filter cannot be derived from its type name:

public class OrdersFilter : Filter
{
    public override string Name =&gt; "OrderIdList";

    public override string ToString()
    {
        ...
    }
}