| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | public sealed class WebBodyFormatMessageProperty : IMessageProperty |
| | | 10 | | { |
| | | 11 | | public const string Name = "WebBodyFormatMessageProperty"; |
| | | 12 | | |
| | | 13 | | private static WebBodyFormatMessageProperty s_jsonProperty; |
| | | 14 | | private static WebBodyFormatMessageProperty s_xmlProperty; |
| | | 15 | | private static WebBodyFormatMessageProperty s_rawProperty; |
| | | 16 | | |
| | 3 | 17 | | public WebBodyFormatMessageProperty(WebContentFormat format) |
| | | 18 | | { |
| | 3 | 19 | | if (format == WebContentFormat.Default) |
| | | 20 | | { |
| | 0 | 21 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.DefaultCont |
| | | 22 | | } |
| | | 23 | | |
| | 3 | 24 | | Format = format; |
| | 3 | 25 | | } |
| | | 26 | | |
| | 64 | 27 | | public WebContentFormat Format { get; } |
| | | 28 | | |
| | | 29 | | internal static WebBodyFormatMessageProperty JsonProperty |
| | | 30 | | { |
| | | 31 | | get |
| | | 32 | | { |
| | 30 | 33 | | if (s_jsonProperty == null) |
| | | 34 | | { |
| | 1 | 35 | | s_jsonProperty = new WebBodyFormatMessageProperty(WebContentFormat.Json); |
| | | 36 | | } |
| | | 37 | | |
| | 30 | 38 | | return s_jsonProperty; |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | internal static WebBodyFormatMessageProperty XmlProperty |
| | | 43 | | { |
| | | 44 | | get |
| | | 45 | | { |
| | 2 | 46 | | if (s_xmlProperty == null) |
| | | 47 | | { |
| | 1 | 48 | | s_xmlProperty = new WebBodyFormatMessageProperty(WebContentFormat.Xml); |
| | | 49 | | } |
| | | 50 | | |
| | 2 | 51 | | return s_xmlProperty; |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | internal static WebBodyFormatMessageProperty RawProperty |
| | | 56 | | { |
| | | 57 | | get |
| | | 58 | | { |
| | 8 | 59 | | if (s_rawProperty == null) |
| | | 60 | | { |
| | 1 | 61 | | s_rawProperty = new WebBodyFormatMessageProperty(WebContentFormat.Raw); |
| | | 62 | | } |
| | | 63 | | |
| | 8 | 64 | | return s_rawProperty; |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | |
| | 40 | 68 | | public IMessageProperty CreateCopy() => this; |
| | | 69 | | |
| | 0 | 70 | | public override string ToString() => string.Format(CultureInfo.InvariantCulture, SR.Format(SR.WebBodyFormatPrope |
| | | 71 | | } |
| | | 72 | | } |