Использование ASP.NET Web API. Есть ли способ автоматически возвращать код состояния 400, если параметр имеет значение null? Я нашел это question, но это глобальное решение, применяемое ко всем методам, я хочу сделать это по каждому методу на каждый параметр.
Итак, например, это то, что я сейчас делаю:
public HttpResponseMessage SomeMethod(SomeNullableParameter parameter)
{
if (parameter == null)
throw new HttpResponseException(HttpStatusCode.BadRequest);
// Otherwise do more stuff.
}
Я бы просто хотел сделать что-то вроде этого (обратите внимание на требуемый атрибут):
public HttpResponseMessage SomeMethod([Required] SomeNullableParameter parameter)
{
// Do stuff.
}