Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Nullable DateTimes #112

Open
ngm opened this issue Jul 7, 2016 · 1 comment
Open

Error with Nullable DateTimes #112

ngm opened this issue Jul 7, 2016 · 1 comment

Comments

@ngm
Copy link

ngm commented Jul 7, 2016

If I create a method on an ApiController with a nullable DateTime as a parameter, e.g.:

[Route("nullabledate")]
public void NullableDateTest(DateTime? nullableDate)
{
    Console.Write(nullableDate);
}

When generating the C# client with WebApiProxy-Generate-CSharp, I get the following code in WebApiProxy.generated.cs:

/// <summary>
/// 
/// </summary>
/// <param name="nullableDate"></param>
/// <returns></returns>
protected virtual async Task<HttpResponseMessage> NullableDateTestAsyncMsg(Nullable<DateTime> nullableDate)
{
    return await HttpClient.PostAsJsonAsync("profiles/nullabledate?nullableDate=" + nullableDate.ToString("o"), default(HttpResponseMessage));
}

/// <summary>
/// 
/// </summary>
/// <param name="nullableDate"></param>
/// <returns></returns>
public virtual async Task<HttpResponseMessage> NullableDateTestAsync(Nullable<DateTime> nullableDate)
{
    return await HttpClient.PostAsJsonAsync("profiles/nullabledate?nullableDate=" + nullableDate.ToString("o"), default(HttpResponseMessage));
}

The calls to nullableDate.ToString("o") produce the following error:

No overload for method 'ToString' takes 1 arguments

Is there a way to get around this?

@ngm
Copy link
Author

ngm commented Jul 7, 2016

I haven't tested it very thoroughly, but the following change works for me for now:

ngm@babd3d2

Basically - if it's a Nullable<DateTime>, then ToString("o") its .Value, otherwise return the empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant