ProducesAttribute Class

A filter that specifies the expected System.Type the action will return and the supported response content types. The Microsoft.AspNetCore.Mvc.ProducesAttribute.ContentTypes value is used to set Microsoft.AspNetCore.Mvc.ObjectResult.ContentTypes.

Namespace
Microsoft.AspNetCore.Mvc
Assemblies
  • Microsoft.AspNetCore.Mvc.Core

Syntax

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class ProducesAttribute : ResultFilterAttribute, _Attribute, IResultFilter, IAsyncResultFilter, IOrderedFilter, IFilterMetadata, IApiResponseMetadataProvider
class Microsoft.AspNetCore.Mvc.ProducesAttribute

Constructors

ProducesAttribute(System.String, System.String[])

Initializes an instance of Microsoft.AspNetCore.Mvc.ProducesAttribute with allowed content types.

Arguments:
  • contentType (System.String) – The allowed content type for a response.
  • additionalContentTypes (System.String<System.String>[]) – Additional allowed content types for a response.
public ProducesAttribute(string contentType, params string[] additionalContentTypes)
ProducesAttribute(System.Type)

Initializes an instance of Microsoft.AspNetCore.Mvc.ProducesAttribute.

Arguments:type (System.Type) – The Microsoft.AspNetCore.Mvc.ProducesAttribute.Type of object that is going to be written in the response.
public ProducesAttribute(Type type)

Properties

Microsoft.AspNetCore.Mvc.ProducesAttribute.ContentTypes

Gets or sets the supported response content types. Used to set Microsoft.AspNetCore.Mvc.ObjectResult.ContentTypes.

Return type:Microsoft.AspNetCore.Mvc.Formatters.MediaTypeCollection
public MediaTypeCollection ContentTypes { get; set; }
Microsoft.AspNetCore.Mvc.ProducesAttribute.StatusCode
Return type:System.Int32
public int StatusCode { get; }
Microsoft.AspNetCore.Mvc.ProducesAttribute.Type
Return type:System.Type
public Type Type { get; set; }

Methods

OnResultExecuting(Microsoft.AspNetCore.Mvc.Filters.ResultExecutingContext)
public override void OnResultExecuting(ResultExecutingContext context)
SetContentTypes(Microsoft.AspNetCore.Mvc.Formatters.MediaTypeCollection)
public void SetContentTypes(MediaTypeCollection contentTypes)