Я преобразовал проект web-проекта С# в F #, используя шаблоны F # ASP.NET. Все работает отлично, за исключением необязательных параметров запроса. Я продолжаю получать эту ошибку
{
"message": "The request is invalid.",
"messageDetail": "The parameters dictionary contains an invalid entry for parameter 'start' for method 'System.Threading.Tasks.Task`1[System.Net.Http.HttpResponseMessage] GetVendorFiles(Int32, System.Nullable`1[System.DateTime])' in 'Thor.WebApi.VendorFilesController'. The dictionary contains a value of type 'System.Reflection.Missing', but the parameter requires a value of type 'System.Nullable`1[System.DateTime]'."
}
Функциональная подпись F #:
[<HttpGet; Route("")>]
member x.GetVendorFiles( [<Optional; DefaultParameterValue(100)>] count, [<Optional; DefaultParameterValue(null)>] start : Nullable<DateTime> ) =
Функциональная подпись С#:
[HttpGet]
[Route("")]
public async Task<HttpResponseMessage> GetVendorFiles(int count = 100,DateTime? start = null)
Кто-нибудь знает об обходных решениях?
Обновлено:
Я понял причину этой проблемы. ASP.NET извлекает значения по умолчанию для действий контроллера с помощью ParameterInfo. По-видимому, компилятор F # не компилирует значения по умолчанию так же, как С# (даже с DefaultParameterValueAttribute
)
Какой лучший способ или обходится это? Будет ли это какой-то фильтр, который мне нужно внедрить или реализовать собственный ParameterBinding
?