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


C# StringContent.Clear方法代码示例

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


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

示例1: Should_read_serialized_object_from_stream_using_date_handler

        public void Should_read_serialized_object_from_stream_using_date_handler()
        {
            var formatter = new ServiceStackTextFormatter(JsonDateHandler.DCJSCompatible);
            var value = GetTestObject();
            var utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

            JsConfig.DateHandler = JsonDateHandler.DCJSCompatible;
            byte[] data = utf8Encoding.GetBytes(value.ToJson());
            JsConfig.Reset();

            var memoryStream = new MemoryStream(data);

            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();

            var resultTask = formatter.ReadFromStreamAsync(typeof(RootClass), memoryStream, contentHeader, new FormatterContext(StandardMediaTypeHeaderValues.ApplicationJson, isRead: false));

            resultTask.Wait();

            resultTask.Result.ShouldBeType<RootClass>();

            var result = (RootClass)resultTask.Result;

            result.StringProperty.ShouldEqual(value.StringProperty);
            result.DateProperty.ShouldEqual(value.DateProperty);
            result.Child.BooleanProperty.ShouldEqual(value.Child.BooleanProperty);
            result.Child.DecimalProperty.ShouldEqual(value.Child.DecimalProperty);
            result.Child.DoubleProperty.ShouldEqual(value.Child.DoubleProperty);
            result.Child.IntegerProperty.ShouldEqual(value.Child.IntegerProperty);
            result.Child.StringProperty.ShouldEqual(value.Child.StringProperty);
        }
开发者ID:rmueller,项目名称:WebAPIContrib,代码行数:31,代码来源:ServiceStackTextFormatterTests.cs

示例2: Should_read_serialized_object_from_stream

        public void Should_read_serialized_object_from_stream()
        {
            var formatter = new ServiceStackTextFormatter();
            var value = GetTestObject();
            var utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

            //Media Type Formatter uses ISO8601 date formatting by default;
            JsConfig.DateHandler = JsonDateHandler.ISO8601;
            byte[] data = utf8Encoding.GetBytes(value.ToJson());
            JsConfig.Reset();
            var memoryStream = new MemoryStream(data);

            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();

            var resultTask = formatter.ReadFromStreamAsync(typeof(RootClass), memoryStream, contentHeader, null);

            resultTask.Wait();

            resultTask.Result.ShouldBeType<RootClass>();

            var result = (RootClass)resultTask.Result;

            result.StringProperty.ShouldEqual(value.StringProperty);
            result.DateProperty.ShouldEqual(value.DateProperty);
            result.Child.BooleanProperty.ShouldEqual(value.Child.BooleanProperty);
            result.Child.DecimalProperty.ShouldEqual(value.Child.DecimalProperty);
            result.Child.DoubleProperty.ShouldEqual(value.Child.DoubleProperty);
            result.Child.IntegerProperty.ShouldEqual(value.Child.IntegerProperty);
            result.Child.StringProperty.ShouldEqual(value.Child.StringProperty);
        }
开发者ID:andreabalducci,项目名称:WebAPIContrib,代码行数:31,代码来源:ServiceStackTextFormatterTests.cs

示例3: Should_write_string_to_stream

        public void Should_write_string_to_stream()
        {
            var formatter = new PlainTextFormatter();

            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();
            var memoryStream = new MemoryStream();
            var value = "Hello World";
            var resultTask = formatter.WriteToStreamAsync(typeof(string), value, memoryStream, contentHeader, transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            serializedString.ShouldEqual(value);
        }
开发者ID:joeyburgett,项目名称:WebAPIContrib,代码行数:17,代码来源:PlainTextFormatterTests.cs

示例4: Should_read_serialized_object_from_stream

        public void Should_read_serialized_object_from_stream()
        {
            var formatter = new PlainTextFormatter();
            var value = "Hello World";

            var memoryStream = new MemoryStream();
            var sr = new StreamWriter(memoryStream);
            sr.Write(value);
            sr.Flush();
            memoryStream.Position = 0;
            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();

            var resultTask = formatter.ReadFromStreamAsync(typeof(string), memoryStream, contentHeader, null);

            resultTask.Wait();

            resultTask.Result.ShouldBeType<String>();

            var result = (String)resultTask.Result;

            result.ShouldEqual(value);
        }
开发者ID:joeyburgett,项目名称:WebAPIContrib,代码行数:23,代码来源:PlainTextFormatterTests.cs

示例5: Should_write_serialized_object_to_stream

        public void Should_write_serialized_object_to_stream()
        {
            var formatter = new ServiceStackTextFormatter();
            var value = GetTestObject();

            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();
            var memoryStream = new MemoryStream();

            var resultTask = formatter.WriteToStreamAsync(typeof(RootClass), value, memoryStream, contentHeader, new FormatterContext(StandardMediaTypeHeaderValues.ApplicationJson, isRead: false), transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            // Formatter uses ISO8601 dates by default
            JsConfig.DateHandler = JsonDateHandler.ISO8601;
            var expextedResult = value.ToJson();
            JsConfig.Reset();
            serializedString.ShouldEqual(expextedResult);
        }
开发者ID:rmueller,项目名称:WebAPIContrib,代码行数:22,代码来源:ServiceStackTextFormatterTests.cs

示例6: Should_write_serialized_object_to_stream_using_date_handler

        public void Should_write_serialized_object_to_stream_using_date_handler()
        {
            var formatter = new ServiceStackTextFormatter(JsonDateHandler.TimestampOffset);
            var value = GetTestObject();

            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();
            var memoryStream = new MemoryStream();

            var resultTask = formatter.WriteToStreamAsync(typeof(RootClass), value, memoryStream, contentHeader, transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            JsConfig.DateHandler = JsonDateHandler.TimestampOffset;
            var expected = value.ToJson();
            JsConfig.Reset();
            serializedString.ShouldEqual(expected);
        }
开发者ID:andreabalducci,项目名称:WebAPIContrib,代码行数:21,代码来源:ServiceStackTextFormatterTests.cs


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