public bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (typeof(ResourceResult).GetTypeInfo().IsAssignableFrom(context.ObjectType.GetTypeInfo()))
                return true;

            return false;
        }
        /// <inheritdoc />
        public bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            // ignore the contentType and just look at the content.
            // This formatter will be selected if the content is null.
            // We check for Task as a user can directly create an ObjectContentResult with the unwrapped type.
            if (context.ObjectType == typeof(void) || context.ObjectType == typeof(Task))
            {
                return true;
            }

            return TreatNullValueAsNoContent && context.Object == null;
        }
Example #3
0
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     if (base.CanWriteResult(context))
     {
         var actionReturnString = context.Object as string;
         if (actionReturnString != null)
         {
             return true;
         }
     }
     return false;
 }
Example #4
0
        /// <inheritdoc />
        public bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            // ignore the contentType and just look at the content.
            // This formatter will be selected if the content is null.
            // We check for Task as a user can directly create an ObjectContentResult with the unwrapped type.
            if (context.ObjectType == typeof(void) || context.ObjectType == typeof(Task))
            {
                return(true);
            }

            return(TreatNullValueAsNoContent && context.Object == null);
        }
        /// <inheritdoc />
        public bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Ignore the passed in content type, if the object is a Stream.
            if (context.Object is Stream)
            {
                return true;
            }

            return false;
        }
Example #6
0
        /// <inheritdoc />
        public bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Ignore the passed in content type, if the object is a Stream.
            if (context.Object is Stream)
            {
                return(true);
            }

            return(false);
        }
Example #7
0
        public override bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (base.CanWriteResult(context))
            {
                if (context.Object is Product)
                {
                    return true;
                }

                if (context.Object is string)
                {
                    return true;
                }
            }

            return false;
        }
Example #8
0
        public override bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Ignore the passed in content type, if the object is string
            // always return it as a text/plain format.
            if (context.ObjectType == typeof(string) || context.Object is string)
            {
                context.ContentType = SupportedMediaTypes[0];
                return(true);
            }

            return(false);
        }
        public override bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Ignore the passed in content type, if the object is string
            // always return it as a text/plain format.
            if (context.ObjectType == typeof(string) || context.Object is string)
            {
                context.ContentType = SupportedMediaTypes[0];
                return true;
            }

            return false;
        }
Example #10
0
        /// <inheritdoc />
        public virtual bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!CanWriteType(context.ObjectType))
            {
                return(false);
            }

            if (context.ContentType == null)
            {
                // If the desired content type is set to null, then the current formatter can write anything
                // it wants.
                if (SupportedMediaTypes.Count > 0)
                {
                    context.ContentType = SupportedMediaTypes[0];
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                // Confirm this formatter supports a more specific media type than requested e.g. OK if "text/*"
                // requested and formatter supports "text/plain". contentType is typically what we got in an Accept
                // header.
                for (var i = 0; i < SupportedMediaTypes.Count; i++)
                {
                    var mediaType = SupportedMediaTypes[i];
                    if (mediaType.IsSubsetOf(context.ContentType))
                    {
                        context.ContentType = mediaType;
                        return(true);
                    }
                }
            }

            return(false);
        }
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return context.ObjectType == typeof(QuerySummary);
 }
 public virtual bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return false;
 }
Example #13
0
        /// <inheritdoc />
        public virtual bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            
            if (!CanWriteType(context.ObjectType))
            {
                return false;
            }
            
            if (context.ContentType == null)
            {
                // If the desired content type is set to null, then the current formatter can write anything
                // it wants.
                if (SupportedMediaTypes.Count > 0)
                {
                    context.ContentType = SupportedMediaTypes[0];
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                // Confirm this formatter supports a more specific media type than requested e.g. OK if "text/*"
                // requested and formatter supports "text/plain". contentType is typically what we got in an Accept
                // header.
                for (var i = 0; i < SupportedMediaTypes.Count; i++)
                {
                    var mediaType = SupportedMediaTypes[i];
                    if (mediaType.IsSubsetOf(context.ContentType))
                    {
                        context.ContentType = mediaType;
                        return true;
                    }
                }
            }

            return false;
        }
Example #14
0
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     // Do not set the selected media Type.
     // The WriteResponseHeaders should do it for you.
     return(true);
 }
 /// <inheritdoc />
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return(context.FailedContentNegotiation ?? false);
 }
Example #16
0
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return true;
 }
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return context.Object is HttpResponseMessage;
 }
Example #18
0
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     // Do not set the selected media Type.
     // The WriteResponseHeaders should do it for you.
     return true;
 }
 /// <inheritdoc />
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return context.FailedContentNegotiation ?? false;
 }