コード例 #1
0
        public bool CanWriteResult(OutputFormatterCanWriteContext context)
        {
            if (typeof(ResourceResult).GetTypeInfo().IsAssignableFrom(context.ObjectType.GetTypeInfo()))
                return true;

            return false;
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: CustomFormatter.cs プロジェクト: huoxudong125/Mvc
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     if (base.CanWriteResult(context))
     {
         var actionReturnString = context.Object as string;
         if (actionReturnString != null)
         {
             return true;
         }
     }
     return false;
 }
コード例 #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);
        }
コード例 #5
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;
        }
コード例 #6
0
ファイル: StreamOutputFormatter.cs プロジェクト: zyonet/Mvc
        /// <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);
        }
コード例 #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;
        }
コード例 #8
0
ファイル: StringOutputFormatter.cs プロジェクト: zyonet/Mvc
        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);
        }
コード例 #9
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;
        }
コード例 #10
0
ファイル: OutputFormatter.cs プロジェクト: zyonet/Mvc
        /// <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);
        }
コード例 #11
0
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return context.ObjectType == typeof(QuerySummary);
 }
コード例 #12
0
 public virtual bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return false;
 }
コード例 #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;
        }
コード例 #14
0
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     // Do not set the selected media Type.
     // The WriteResponseHeaders should do it for you.
     return(true);
 }
コード例 #15
0
 /// <inheritdoc />
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return(context.FailedContentNegotiation ?? false);
 }
コード例 #16
0
ファイル: ObjectResultTests.cs プロジェクト: huoxudong125/Mvc
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return true;
 }
コード例 #17
0
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return context.Object is HttpResponseMessage;
 }
コード例 #18
0
 public override bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     // Do not set the selected media Type.
     // The WriteResponseHeaders should do it for you.
     return true;
 }
コード例 #19
0
 /// <inheritdoc />
 public bool CanWriteResult(OutputFormatterCanWriteContext context)
 {
     return context.FailedContentNegotiation ?? false;
 }