C# MemoryStream.WriteTo的代码示例

通过代码示例来学习C# MemoryStream.WriteTo方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


MemoryStream.WriteTo是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.WriteTo() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.WriteTo() 方法的写法,从而快速掌握该方法的应用。

MemoryStream.WriteTo的代码示例1 - Decompress()

    using System.IO;
        #endregion

        #region Method: Decompress
        /// 
        /// Attempts to decompress the given input by letting all contained formats
        /// try to decompress the input.
        /// 
        public override long Decompress(System.IO.Stream instream, long inLength, System.IO.Stream outstream)
        {
            byte[] inputData = new byte[instream.Length];
            instream.Read(inputData, 0, inputData.Length);

            foreach (CompressionFormat format in this.formats)
            {
                if (!format.SupportsDecompression)
                    continue;
                using (MemoryStream input = new MemoryStream(inputData))
                {
                    if (!format.Supports(input, inputData.Length))
                        continue;
                    MemoryStream output = new MemoryStream();
                    try
                    {
                        long decLength = format.Decompress(input, inputData.Length, output);
                        if (decLength > 0)
                        {
                            output.WriteTo(outstream);
                            return decLength;
                        }
                    }
                    catch (Exception) { continue; }
                }
            }

            throw new InvalidDataException("Input cannot be decompressed using the " + this.ShortFormatString + " formats.");
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:37,代码来源:CompositeFormat.cs

在Decompress()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例2 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoCSVRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder csv = new StringBuilder();
                configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoCSVWriter(csv, configuration))
                    w.Write(rec as DataTable);
                return csv.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder csv = new StringBuilder();
                configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoCSVWriter(csv, configuration))
                    w.Write(rec as IDataReader);
                return csv.ToString();
            }

            ChoCSVRecordWriter writer = new ChoCSVRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:35,代码来源:ChoCSVWriter.cs

在ToText()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例3 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoFixedLengthRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder text = new StringBuilder();
                configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoFixedLengthWriter(text, configuration))
                    w.Write(rec as DataTable);
                return text.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder text = new StringBuilder();
                configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoFixedLengthWriter(text, configuration))
                    w.Write(rec as IDataReader);
                return text.ToString();
            }

            ChoFixedLengthRecordWriter writer = new ChoFixedLengthRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:35,代码来源:ChoFixedLengthWriter.cs

在ToText()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例4 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoJSONRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoJSONWriter(json, configuration))
                {
                    w.Write(rec as DataTable);
                }
                return json.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoJSONWriter(json, configuration))
                {
                    w.Write(rec as IDataReader);
                }
                return json.ToString();
            }

            ChoJSONRecordWriter writer = new ChoJSONRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:37,代码来源:ChoJSONWriter.cs

在ToText()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例5 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoXmlRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(rec as DataTable);
                return xml.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(rec as IDataReader);
                return xml.ToString();
            }

            ChoXmlRecordWriter writer = new ChoXmlRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:33,代码来源:ChoXmlWriter.cs

在ToText()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例6 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoYamlRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoYamlWriter(json, configuration))
                {
                    w.Write(rec as DataTable);
                }
                return json.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoYamlWriter(json, configuration))
                {
                    w.Write(rec as IDataReader);
                }
                return json.ToString();
            }

            ChoYamlRecordWriter writer = new ChoYamlRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:37,代码来源:ChoYamlWriter.cs

在ToText()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例7 - FileWriteIfDifferentInternal()

    using System.IO;

        internal static bool FileWriteIfDifferentInternal(FileInfo file, MemoryStream stream, bool bypassAutoCleanupDatabase = false)
        {
            if (!bypassAutoCleanupDatabase)
                RecordInAutoCleanupDatabase(file.FullName);

            if (file.Exists)
            {
                if (!IsFileDifferent(file, stream))
                    return false;

                if (file.IsReadOnly)
                    file.IsReadOnly = false;
            }
            else
            {
                // make sure target directory exist
                if (!file.Directory.Exists)
                    file.Directory.Create();
            }

            // write the file
            using (FileStream outStream = file.Open(FileMode.Create))
            {
                stream.WriteTo(outStream);
            }

            return true;
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:30,代码来源:Util.cs

在FileWriteIfDifferentInternal()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

MemoryStream.WriteTo的代码示例8 - NextTest()

    using System.IO;
        [Fact]
        public void NextTest()
        {
            var buf = "Stone".GetBytes();

            var pk = new Packet(buf);
            pk.Append("NewLife".GetBytes());

            Assert.NotNull(pk.Next);
            Assert.Equal("StoneNewLife", pk.ToStr());

            var pk2 = pk.Slice(2, 6);
            Assert.Equal("oneNew", pk2.ToStr());

            var p = pk.IndexOf("eNe".GetBytes());
            Assert.Equal(4, p);

            Assert.Equal("StoneNewLife", pk.ToArray().ToStr());

            Assert.Equal("eNe", pk.ReadBytes(4, 3).ToStr());

            var arr = pk.ToSegment();
            Assert.Equal("StoneNewLife", arr.Array.ToStr());
            Assert.Equal(0, arr.Offset);
            Assert.Equal(5 + 7, arr.Count);

            var arrs = pk.ToSegments();
            Assert.Equal(2, arrs.Count);
            Assert.Equal("Stone", arrs[0].Array.ToStr());
            Assert.Equal("NewLife", arrs[1].Array.ToStr());

            var ms = pk.GetStream();
            Assert.Equal(0, ms.Position);
            Assert.Equal(5 + 7, ms.Length);
            Assert.Equal("StoneNewLife", ms.ToStr());

            ms = new MemoryStream();
            pk.CopyTo(ms);
            Assert.Equal(5 + 7, ms.Position);
            Assert.Equal(5 + 7, ms.Length);
            ms.Position = 0;
            Assert.Equal("StoneNewLife", ms.ToStr());

            ms = new MemoryStream();
            pk.CopyToAsync(ms).Wait();
            Assert.Equal(5 + 7, ms.Position);
            Assert.Equal(5 + 7, ms.Length);
            ms.Position = 0;
            Assert.Equal("StoneNewLife", ms.ToStr());

            var buf2 = new Byte[7];
            pk.WriteTo(buf2, 1, 5);
            Assert.Equal(0, buf2[0]);
            Assert.Equal(0, buf2[6]);
            Assert.Equal("Stone", buf2.ToStr(null, 1, 5));

            var pk3 = pk.Clone();
            Assert.NotEqual(pk.Data, pk3.Data);
            Assert.Equal(pk.Total, pk3.Total);
            Assert.NotEqual(pk.Count, pk3.Count);
            Assert.Null(pk3.Next);
        }
    

开发者ID:NewLifeX,项目名称:X,代码行数:63,代码来源:PacketTests.cs

在NextTest()方法中,MemoryStream的代码示例类中的WriteTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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