Skip to content
Discussion options

You must be logged in to vote

Two options:

Per-parameter via the Query attribute Format property:

[Get("/events")]
Task GetEvents([Query(Format = "o")] DateTime from);

Global, for every DateTime in URLs - implement IUrlParameterFormatter and set it on RefitSettings:

class Iso8601UrlParameterFormatter : DefaultUrlParameterFormatter
{
    public override string? Format(object? value, ICustomAttributeProvider attributeProvider, Type type)
    {
        if (value is DateTime dt)
            return dt.ToString("o", CultureInfo.InvariantCulture);
        if (value is DateTimeOffset dto)
            return dto.ToString("o", CultureInfo.InvariantCulture);
        return base.Format(value, attributeProvider, type);
    }
}

var 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants