| | | 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.Diagnostics.CodeAnalysis; |
| | | 6 | | |
| | | 7 | | namespace System.Net.Http.Headers |
| | | 8 | | { |
| | | 9 | | public sealed class MediaTypeWithQualityHeaderValue : MediaTypeHeaderValue, ICloneable |
| | | 10 | | { |
| | | 11 | | public double? Quality |
| | | 12 | | { |
| | 0 | 13 | | get => HeaderUtilities.GetQuality((UnvalidatedObjectCollection<NameValueHeaderValue>)Parameters); |
| | 0 | 14 | | set => HeaderUtilities.SetQuality((UnvalidatedObjectCollection<NameValueHeaderValue>)Parameters, value); |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | internal MediaTypeWithQualityHeaderValue() |
| | 3849 | 18 | | : base() |
| | 3849 | 19 | | { |
| | | 20 | | // Used by the parser to create a new instance of this type. |
| | 3849 | 21 | | } |
| | | 22 | | |
| | | 23 | | public MediaTypeWithQualityHeaderValue(string mediaType) |
| | 0 | 24 | | : base(mediaType) |
| | 0 | 25 | | { |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | public MediaTypeWithQualityHeaderValue(string mediaType, double quality) |
| | 0 | 29 | | : base(mediaType) |
| | 0 | 30 | | { |
| | 0 | 31 | | Quality = quality; |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | private MediaTypeWithQualityHeaderValue(MediaTypeWithQualityHeaderValue source) |
| | 0 | 35 | | : base(source) |
| | 0 | 36 | | { |
| | | 37 | | // No additional members to initialize here. This constructor is used by Clone(). |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | object ICloneable.Clone() |
| | 0 | 41 | | { |
| | 0 | 42 | | return new MediaTypeWithQualityHeaderValue(this); |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | public static new MediaTypeWithQualityHeaderValue Parse(string input) |
| | 0 | 46 | | { |
| | 0 | 47 | | int index = 0; |
| | 0 | 48 | | return (MediaTypeWithQualityHeaderValue)MediaTypeHeaderParser.SingleValueWithQualityParser.ParseValue( |
| | 0 | 49 | | input, null, ref index); |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | public static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out MediaTypeWithQualityHeade |
| | 0 | 53 | | { |
| | 0 | 54 | | int index = 0; |
| | 0 | 55 | | parsedValue = null; |
| | | 56 | | |
| | 0 | 57 | | if (MediaTypeHeaderParser.SingleValueWithQualityParser.TryParseValue(input, null, ref index, out object? out |
| | 0 | 58 | | { |
| | 0 | 59 | | parsedValue = (MediaTypeWithQualityHeaderValue)output!; |
| | 0 | 60 | | return true; |
| | | 61 | | } |
| | 0 | 62 | | return false; |
| | 0 | 63 | | } |
| | | 64 | | } |
| | | 65 | | } |