当前位置: 首页>>代码示例>>C#>>正文


C# HttpHeaderValueCollection.CopyTo方法代码示例

本文整理汇总了C#中HttpHeaderValueCollection.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaderValueCollection.CopyTo方法的具体用法?C# HttpHeaderValueCollection.CopyTo怎么用?C# HttpHeaderValueCollection.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpHeaderValueCollection的用法示例。


在下文中一共展示了HttpHeaderValueCollection.CopyTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyTo_ArrayTooSmall_Throw

        public void CopyTo_ArrayTooSmall_Throw()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string)));
            HttpHeaderValueCollection<string> collection = new HttpHeaderValueCollection<string>(knownHeader, headers,
                "special");

            string[] array = new string[1];
            array[0] = null;

            collection.CopyTo(array, 0); // no exception
            Assert.Null(array[0]);

            Assert.Throws<ArgumentNullException>(() => { collection.CopyTo(null, 0); });
            Assert.Throws<ArgumentOutOfRangeException>(() => { collection.CopyTo(array, -1); });
            Assert.Throws<ArgumentOutOfRangeException>(() => { collection.CopyTo(array, 2); });

            headers.Add(knownHeader, "special");
            array = new string[0];
            Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); });

            headers.Add(knownHeader, "special");
            headers.Add(knownHeader, "special");
            array = new string[1];
            Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); });

            headers.Add(knownHeader, "value1");
            array = new string[0];
            Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); });

            headers.Add(knownHeader, "value2");
            array = new string[1];
            Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 0); });

            array = new string[2];
            Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 1); });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:36,代码来源:HttpHeaderValueCollectionTest.cs

示例2: CopyTo_AddValuesAndSpecialValue_AllValuesCopied

        public void CopyTo_AddValuesAndSpecialValue_AllValuesCopied()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/1/"));
            collection.Add(new Uri("http://www.example.org/2/"));
            collection.SetSpecialValue();
            collection.Add(new Uri("http://www.example.org/3/"));

            Uri[] array = new Uri[5];
            collection.CopyTo(array, 1);

            Assert.Null(array[0]);
            Assert.Equal(new Uri("http://www.example.org/1/"), array[1]);
            Assert.Equal(new Uri("http://www.example.org/2/"), array[2]);
            Assert.Equal(specialValue, array[3]);
            Assert.Equal(new Uri("http://www.example.org/3/"), array[4]);

            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
        }
开发者ID:dotnet,项目名称:corefx,代码行数:22,代码来源:HttpHeaderValueCollectionTest.cs

示例3: CopyTo_OnlySpecialValueEmptyDestination_Copied

        public void CopyTo_OnlySpecialValueEmptyDestination_Copied()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.SetSpecialValue();
            headers.Add(knownHeader, specialValue.ToString());

            Uri[] array = new Uri[2];
            collection.CopyTo(array, 0);

            Assert.Equal(specialValue, array[0]);
            Assert.Equal(specialValue, array[1]);

            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:HttpHeaderValueCollectionTest.cs

示例4: CopyTo_AddMultipleValues_ContainsAllValuesInTheRightOrder

        public void CopyTo_AddMultipleValues_ContainsAllValuesInTheRightOrder()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            collection.Add(new Uri("http://www.example.org/1/"));
            collection.Add(new Uri("http://www.example.org/2/"));
            collection.Add(new Uri("http://www.example.org/3/"));

            Uri[] array = new Uri[5];
            collection.CopyTo(array, 1);

            Assert.Null(array[0]);
            Assert.Equal(new Uri("http://www.example.org/1/"), array[1]);
            Assert.Equal(new Uri("http://www.example.org/2/"), array[2]);
            Assert.Equal(new Uri("http://www.example.org/3/"), array[3]);
            Assert.Null(array[4]);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:HttpHeaderValueCollectionTest.cs

示例5: CopyTo_AddSingleValue_ContainsSingleValue

        public void CopyTo_AddSingleValue_ContainsSingleValue()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/"));

            Uri[] array = new Uri[1];
            collection.CopyTo(array, 0);
            Assert.Equal(new Uri("http://www.example.org/"), array[0]);

            // Now only set the special value: nothing should be added to the array.
            headers.Clear();
            headers.Add(knownHeader, specialValue.ToString());
            array[0] = null;
            collection.CopyTo(array, 0);
            Assert.Equal(specialValue, array[0]);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:19,代码来源:HttpHeaderValueCollectionTest.cs

示例6: CopyTo_NoValues_DoesNotChangeArray

        public void CopyTo_NoValues_DoesNotChangeArray()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            Uri[] array = new Uri[4];
            collection.CopyTo(array, 0);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.Null(array[i]);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:HttpHeaderValueCollectionTest.cs

示例7: CopyTo_EmptyToEmpty_Success

        public void CopyTo_EmptyToEmpty_Success()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            Uri[] array = new Uri[0];
            collection.CopyTo(array, 0);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:HttpHeaderValueCollectionTest.cs

示例8: CopyTo_CallWithStartIndexPlusElementCountGreaterArrayLength_Throw

        public void CopyTo_CallWithStartIndexPlusElementCountGreaterArrayLength_Throw()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            collection.Add(new Uri("http://www.example.org/1/"));
            collection.Add(new Uri("http://www.example.org/2/"));

            Uri[] array = new Uri[2];
            
            // startIndex + Count = 1 + 2 > array.Length
            Assert.Throws<ArgumentException>(() => { collection.CopyTo(array, 1); });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:HttpHeaderValueCollectionTest.cs


注:本文中的HttpHeaderValueCollection.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。