Esempio n. 1
0
        internal static TimeSpan?GetTimeSpanValue(
            HeaderDescriptor descriptor,
            HttpHeaders store)
        {
            object parsedValues = store.GetParsedValues(descriptor);

            return(parsedValues != null ? new TimeSpan?((TimeSpan)parsedValues) : new TimeSpan?());
        }
Esempio n. 2
0
        internal static TimeSpan?GetTimeSpanValue(string headerName, HttpHeaders store)
        {
            Debug.Assert(store != null);

            object storedValue = store.GetParsedValues(headerName);

            if (storedValue != null)
            {
                return((TimeSpan)storedValue);
            }
            return(null);
        }
Esempio n. 3
0
        internal static DateTimeOffset?GetDateTimeOffsetValue(string headerName, HttpHeaders store)
        {
            Debug.Assert(store != null);

            object storedValue = store.GetParsedValues(headerName);

            if (storedValue != null)
            {
                return((DateTimeOffset)storedValue);
            }
            return(null);
        }
Esempio n. 4
0
        internal static TimeSpan?GetTimeSpanValue(HeaderDescriptor descriptor, HttpHeaders store)
        {
            Debug.Assert(store != null);

            object storedValue = store.GetParsedValues(descriptor);

            if (storedValue != null)
            {
                return((TimeSpan)storedValue);
            }
            return(null);
        }
Esempio n. 5
0
        internal static TimeSpan?GetTimeSpanValue(string headerName, HttpHeaders store)
        {
            Contract.Requires(store != null);

            object storedValue = store.GetParsedValues(headerName);

            if (storedValue != null)
            {
                return((TimeSpan)storedValue);
            }
            return(null);
        }
Esempio n. 6
0
        internal static DateTimeOffset?GetDateTimeOffsetValue(HeaderDescriptor descriptor, HttpHeaders store)
        {
            Debug.Assert(store != null);

            object storedValue = store.GetParsedValues(descriptor);

            if (storedValue != null)
            {
                return((DateTimeOffset)storedValue);
            }
            return(null);
        }
Esempio n. 7
0
        internal static DateTimeOffset?GetDateTimeOffsetValue(
            HeaderDescriptor descriptor,
            HttpHeaders store,
            DateTimeOffset?defaultValue = null)
        {
            object parsedValues = store.GetParsedValues(descriptor);

            if (parsedValues != null)
            {
                return(new DateTimeOffset?((DateTimeOffset)parsedValues));
            }
            return(defaultValue.HasValue && store.Contains(descriptor) ? defaultValue : new DateTimeOffset?());
        }
Esempio n. 8
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            // Allow arrayIndex == array.Length in case our own collection is empty
            if ((arrayIndex < 0) || (arrayIndex > array.Length))
            {
                throw new ArgumentOutOfRangeException(nameof(arrayIndex));
            }

            object?storeValue = _store.GetParsedValues(_descriptor);

            if (storeValue == null)
            {
                return;
            }

            List <object>?storeValues = storeValue as List <object>;

            if (storeValues == null)
            {
                // We only have 1 value: If it is the "special value" just return, otherwise add the value to the
                // array and return.
                Debug.Assert(storeValue is T);
                if (arrayIndex == array.Length)
                {
                    throw new ArgumentException(SR.net_http_copyto_array_too_small);
                }
                array[arrayIndex] = (T)storeValue;
            }
            else
            {
                storeValues.CopyTo(array, arrayIndex);
            }
        }
Esempio n. 9
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            // Allow arrayIndex == array.Length in case our own collection is empty
            if ((arrayIndex < 0) || (arrayIndex > array.Length))
            {
                throw new ArgumentOutOfRangeException(nameof(arrayIndex));
            }

            object storeValue = _store.GetParsedValues(_headerName);

            if (storeValue == null)
            {
                return;
            }

            List <object> storeValues = storeValue as List <object>;

            if (storeValues == null)
            {
                // We only have 1 value: If it is the "special value" just return, otherwise add the value to the
                // array and return.
                Debug.Assert(storeValue is T);
                if (arrayIndex == array.Length)
                {
                    throw new ArgumentException("The number of elements is greater than the available space from arrayIndex to the end of the destination array.");
                }
                array[arrayIndex] = storeValue as T;
            }
            else
            {
                storeValues.CopyTo(array, arrayIndex);
            }
        }
Esempio n. 10
0
        internal static DateTimeOffset?GetDateTimeOffsetValue(HeaderDescriptor descriptor, HttpHeaders store, DateTimeOffset?defaultValue = null)
        {
            Debug.Assert(store != null);

            object storedValue = store.GetParsedValues(descriptor);

            if (storedValue != null)
            {
                return((DateTimeOffset)storedValue);
            }
            else if (defaultValue != null && store.Contains(descriptor))
            {
                return(defaultValue);
            }

            return(null);
        }
Esempio n. 11
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if ((arrayIndex < 0) || (arrayIndex >= array.Length))
            {
                throw new ArgumentOutOfRangeException("arrayIndex");
            }

            object storeValue = store.GetParsedValues(headerName);

            if (storeValue == null)
            {
                return;
            }

            List <object> storeValues = storeValue as List <object>;

            if (storeValues == null)
            {
                // We only have 1 value: If it is the "special value" just return, otherwise add the value to the
                // array and return.
                Contract.Assert(storeValue is T);
                if (!IsSpecialValue(storeValue))
                {
                    array[arrayIndex] = storeValue as T;
                }
            }
            else
            {
                // We don't know how many values we have. The "special value" may be in the list multiple times. We
                // just know that we'll have at most 'storeValues.Count' values.
                T[] tempArray = new T[storeValues.Count];

                // We have multiple values. Iterate through the values and add them to the array. Skip the
                // "special value" (if present).
                int addedCount = 0;
                foreach (object item in storeValues)
                {
                    if (!IsSpecialValue(item))
                    {
                        // Validate that the destination array has enough space for this value.
                        if (addedCount + arrayIndex >= array.Length)
                        {
                            throw new ArgumentException("The number of elements is greater than the available space from arrayIndex to the end of the destination array.");
                        }

                        Contract.Assert(item is T);
                        tempArray[addedCount] = item as T;
                        addedCount++;
                    }
                }

                // We successfully copied all values to the temp-array and verified that the destination array has
                // enough space to hold the result. Now copy values from the temp array to the destination array.
                if (addedCount > 0)
                {
                    Array.Copy(tempArray, 0, array, arrayIndex, addedCount);
                }
            }
        }