Find() static private method

static private Find ( ObjectCollection values, string name ) : NameValueHeaderValue
values ObjectCollection
name string
return NameValueHeaderValue
Ejemplo n.º 1
0
        internal static void SetQuality(ObjectCollection <NameValueHeaderValue> parameters, double?value)
        {
            Debug.Assert(parameters != null);

            NameValueHeaderValue?qualityParameter = NameValueHeaderValue.Find(parameters, qualityName);

            if (value.HasValue)
            {
                // Note that even if we check the value here, we can't prevent a user from adding an invalid quality
                // value using Parameters.Add(). Even if we would prevent the user from adding an invalid value
                // using Parameters.Add() they could always add invalid values using HttpHeaders.AddWithoutValidation().
                // So this check is really for convenience to show users that they're trying to add an invalid
                // value.
                if ((value < 0) || (value > 1))
                {
                    throw new ArgumentOutOfRangeException(nameof(value));
                }

                string qualityString = ((double)value).ToString("0.0##", NumberFormatInfo.InvariantInfo);
                if (qualityParameter != null)
                {
                    qualityParameter.Value = qualityString;
                }
                else
                {
                    parameters.Add(new NameValueHeaderValue(qualityName, qualityString));
                }
            }
            else
            {
                // Remove quality parameter
                if (qualityParameter != null)
                {
                    parameters.Remove(qualityParameter);
                }
            }
        }
Ejemplo n.º 2
0
        internal static double?GetQuality(UnvalidatedObjectCollection <NameValueHeaderValue> parameters)
        {
            Debug.Assert(parameters != null);

            NameValueHeaderValue?qualityParameter = NameValueHeaderValue.Find(parameters, qualityName);

            if (qualityParameter != null)
            {
                // Note that the RFC requires decimal '.' regardless of the culture. I.e. using ',' as decimal
                // separator is considered invalid (even if the current culture would allow it).
                double qualityValue;
                if (double.TryParse(qualityParameter.Value, NumberStyles.AllowDecimalPoint,
                                    NumberFormatInfo.InvariantInfo, out qualityValue))
                {
                    return(qualityValue);
                }
                // If the stored value is an invalid quality value, just return null and log a warning.
                if (NetEventSource.Log.IsEnabled())
                {
                    NetEventSource.Error(null, SR.Format(SR.net_http_log_headers_invalid_quality, qualityParameter.Value));
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        internal static double?GetQuality(ObjectCollection <NameValueHeaderValue> parameters)
        {
            Contract.Requires(parameters != null);

            NameValueHeaderValue qualityParameter = NameValueHeaderValue.Find(parameters, qualityName);

            if (qualityParameter != null)
            {
                // Note that the RFC requires decimal '.' regardless of the culture. I.e. using ',' as decimal
                // separator is considered invalid (even if the current culture would allow it).
                double qualityValue = 0;
                if (double.TryParse(qualityParameter.Value, NumberStyles.AllowDecimalPoint,
                                    NumberFormatInfo.InvariantInfo, out qualityValue))
                {
                    return(qualityValue);
                }
                // If the stored value is an invalid quality value, just return null and log a warning.
                if (NetEventSource.Log.IsEnabled())
                {
                    NetEventSource.PrintError(NetEventSource.ComponentType.Http, string.Format(System.Globalization.CultureInfo.InvariantCulture, SR.net_http_log_headers_invalid_quality, qualityParameter.Value));
                }
            }
            return(null);
        }