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


C# MemoryStream.SetStreamPosition方法代码示例

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


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

示例1: DeserializeXml

        public void DeserializeXml() {
            var user = Users[0];

            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(user, ms);

                ms.SetStreamPosition();

                var xml = ms.ToText();
                // string xml = StringTool.ToString(ms);

                ms.SetStreamPosition();
                var user2 = XmlTool.Deserialize<User>(ms);

                Assert.AreEqual(user.Id, user2.Id);
                Assert.AreEqual(user.Name, user2.Name);
                Assert.AreEqual(user.Description, user2.Description);

                Assert.IsTrue(user.Equals(user2));
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:21,代码来源:XmlToolFixture.cs

示例2: ToStream

        /// <summary>
        /// 문자열을 기본 인코딩 방식으로 스트림 (<see cref="System.IO.MemoryStream"/>)의 인스턴스로 변환한다.
        /// </summary>
        /// <param name="s">대상문자열</param>
        /// <returns>기본인코딩 방식으로 Stream을 만든다.</returns>
        public static Stream ToStream(this string s) {
            if(s.IsNull())
                return new MemoryStream();

            var stream = new MemoryStream(s.Length * 2);
            var writer = new StreamWriter(stream);

            writer.Write(s);
            writer.Flush();
            stream.SetStreamPosition();

            return stream;
        }
开发者ID:debop,项目名称:NFramework,代码行数:18,代码来源:StringTool.Convert.cs

示例3: SerializeTest

        public void SerializeTest() {
            var user = Users[0];

            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(user, ms);

                ms.SetStreamPosition();

                var str = ms.ToText();
                Assert.IsNotEmpty(str);

                Assert.IsTrue(str.Contains(user.Id.ToString()));
                Console.WriteLine("Serialized Usre=" + str);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:15,代码来源:XmlToolFixture.cs

示例4: Adaptor_Compress_Decompress_By_Stream_InParallel

        public void Adaptor_Compress_Decompress_By_Stream_InParallel() {
            var plainStream = PlainText.ToStream();

            Parallel.ForEach(_compressors,
                             compressor => {
                                 var adapter = new CompressAdapter(compressor);

                                 var compressed = adapter.Compress(plainStream);
                                 var recoveryStream = new MemoryStream(compressed.Length * 2);
                                 adapter.Decompress(compressed, recoveryStream);

                                 // 데이터가 써졌으므로, 다시 원 위치로 설정해줘야 합니다.
                                 recoveryStream.SetStreamPosition();

                                 Assert.IsTrue(recoveryStream.Length > 0);
                                 Assert.AreEqual(PlainText, recoveryStream.ToText());
                             });
        }
开发者ID:debop,项目名称:NFramework,代码行数:18,代码来源:CompressAdaptorTestCase.cs

示例5: Stream_SetStreamPosition_Test2

 public void Stream_SetStreamPosition_Test2()
 {
     using (var ms = new MemoryStream(GetTestBuffer()))
      {
     var position = new StreamPosition(32, null);
     Assert.AreEqual(true, ms.SetStreamPosition(position));
     Assert.AreEqual(32, ms.Position);
      }
 }
开发者ID:harlam357,项目名称:harlam357-net,代码行数:9,代码来源:StreamExtensionsTests.cs

示例6: Stream_SetStreamPosition_Test1

 public void Stream_SetStreamPosition_Test1()
 {
     using (var ms = new MemoryStream(GetTestBuffer()))
      {
     var position = new StreamPosition(128, null);
     Assert.AreEqual(false, ms.SetStreamPosition(position));
     Assert.AreEqual(0, ms.Position);
      }
 }
开发者ID:harlam357,项目名称:harlam357-net,代码行数:9,代码来源:StreamExtensionsTests.cs


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