StatusCode , - :
internal IActionResult CreateResponse(int code, object content = null)
{
Type t = content?.GetType();
bool textContent = t == typeof(string) || t == typeof(bool);
JsonSerializerSettings dateFormatSettings = new JsonSerializerSettings
{
DateFormatString = myDateFormat
};
string bodyContent = content == null || string.IsNullOrWhiteSpace(content + "")
? null
: textContent
? content + ""
: JsonConvert.SerializeObject(content, dateFormatSettings);
ObjectResult or = base.StatusCode(code, bodyContent);
string mediaType =
!textContent
? "application/json"
: "text/plain";
or.ContentTypes.Add(new MediaTypeHeaderValue(mediaType));
return or;
}
:
return base.CreateResponse(StatusCodes.Status200OK, new { name = "My Name", age = 23});
, Ok, BadRequest .., , , - . = 200, - GET. , , , , Type.GetTypeInfo(). IsPrimitive , , DateTime, TimeSpan, DateTimeOffset, Guid.