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


C# this.CopyTo方法代码示例

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


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

示例1: ToByteArray

        /// <summary>
        /// Returns the content of a stream as byte array.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="bufferSize">The custom buffer size to use.</param>
        /// <returns><paramref name="stream" /> as byte array.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="stream" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="bufferSize" /> is invalid.
        /// </exception>
        public static byte[] ToByteArray(this Stream stream, int? bufferSize = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (bufferSize < 1)
            {
                throw new ArgumentOutOfRangeException("stream", bufferSize, "Must be 1 at least!");
            }

            if (stream is MemoryStream)
            {
                return ((MemoryStream)stream).ToArray();
            }

            using (var temp = new MemoryStream())
            {
                if (bufferSize.HasValue)
                {
                    stream.CopyTo(temp, bufferSize.Value);
                }
                else
                {
                    stream.CopyTo(temp);
                }

                return temp.ToArray();
            }
        }
开发者ID:mkloubert,项目名称:Extensions.NET,代码行数:43,代码来源:IO.ToByteArray.cs

示例2: ShouldBeCopiedOK

        internal static void ShouldBeCopiedOK(this IPersistentBufferProvider @this,string iPath)
        {
            bool res = @this.CopyTo(iPath);
            res.Should().BeTrue();

            File.Exists(iPath).Should().BeTrue();

            IPersistentBufferProvider bc = InternalBufferFactory.GetBufferProviderFromFile(iPath);
            bc.Should().NotBeNull();
            @this.Compare(bc).Should().BeTrue();

            @this.CopyTo("").Should().BeFalse();

        }
开发者ID:David-Desmaisons,项目名称:MusicCollection,代码行数:14,代码来源:InternalBufferTestor.cs

示例3: BytesToInt

 /// <summary>
 /// 数组转int,
 /// </summary>
 /// <param name="bytes"></param>
 /// <returns></returns>
 public static Int32 BytesToInt(this Byte[] bytes)
 {
     byte[] intBytes = new byte[4];
     bytes.CopyTo(intBytes, intBytes.Length - bytes.Length);
     if (BitConverter.IsLittleEndian) Array.Reverse(intBytes);
     return BitConverter.ToInt32(intBytes, 0);
 }
开发者ID:wangyang602117818,项目名称:EasyOa.Common,代码行数:12,代码来源:NumberExtentions.cs

示例4: UnpackToDirectory

        public static void UnpackToDirectory(this ZipInputStream zip, string path, IFileSystem fs)
        {
            ZipEntry theEntry;
            while ((theEntry = zip.GetNextEntry()) != null)
            {
                string directoryName = fs.Path.GetDirectoryName(theEntry.Name);
                string fileName = fs.Path.GetFileName(theEntry.Name);

                //Create directory for this entry
                if (!string.IsNullOrEmpty(directoryName))
                    fs.Directory.CreateDirectory(fs.Path.Combine(path, directoryName));

                //If there is no filename this was a directory entry, skip to the next entry
                if (fileName == String.Empty)
                    continue;

                //Copy the file from zip into filesystem
                using (Stream streamWriter = fs.File.Create(fs.Path.Combine(path, theEntry.Name)))
                {
                    zip.CopyTo(streamWriter);
                    streamWriter.Flush();
                }
            }

            Thread.Sleep(100);
        }
开发者ID:xoxota99,项目名称:NodeMachine,代码行数:26,代码来源:ZipInputStreamExtensions.cs

示例5: GetMemoryStream

        public static MemoryStream GetMemoryStream(this Stream stream, int index)
        {
            MemoryStream retVal = null;
            if (stream != null)
            {
                
                MemoryStream wrkStream = null;
                try
                {
                    wrkStream = new MemoryStream();

                    stream.CopyTo(wrkStream, index, stream.Length - index);
                    retVal = wrkStream;
                    retVal.Position = 0;
                    wrkStream = null;
                }
                finally
                {
                    if (wrkStream != null)
                    {
                        wrkStream.Dispose();
                    }
                }
            }
            return retVal;
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:26,代码来源:Utility.cs

示例6: Clone

 /// <summary>
 /// Creates a clone and performs a shallow copy of properties from the source object to the destination
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <returns></returns>
 public static object Clone(this object source, List<String> ExcludeProperties)
 {
     Type t = source.GetType();
     var clone = Activator.CreateInstance(t);
     source.CopyTo(clone, ExcludeProperties);
     return clone;
 }
开发者ID:shenoyroopesh,项目名称:Gama,代码行数:13,代码来源:ExtensionMethods.cs

示例7: AsMemoryStream

        /// <summary>
        /// Returns a <see cref="Stream" /> as a <see cref="MemoryStream" />.
        /// </summary>
        /// <param name="stream">The stream to cast / convert.</param>
        /// <param name="moveToBeginning">Move cursor of result stream to beginning or not.</param>
        /// <returns>The result stream.</returns>
        /// <remarks>
        /// <see langword="null" /> is returned if <paramref name="stream" /> is also <see langword="null" />.
        /// </remarks>
        /// <remarks>
        /// If <paramref name="stream" /> is already a memory stream it is simply casted.
        /// </remarks>
        public static MemoryStream AsMemoryStream(this Stream stream, bool moveToBeginning = true)
        {
            var result = stream as MemoryStream;

            if (result == null && stream != null)
            {
                result = new MemoryStream();
                try
                {
                    stream.CopyTo(result);
                }
                catch
                {
                    result.Dispose();
                    throw;
                }
            }

            if (result != null)
            {
                if (moveToBeginning)
                {
                    result.Position = 0;
                }
            }

            return result;
        }
开发者ID:mkloubert,项目名称:Extensions.NET,代码行数:40,代码来源:IO.AsMemoryStream.cs

示例8: GetString

 public static String GetString(this IList<char> chars)
 {
     char[] array = new char[chars.Count];
     chars.CopyTo(array, 0);
     chars.Clear();
     return new String(array);
 }
开发者ID:jiangguang5201314,项目名称:DotNetFramework,代码行数:7,代码来源:Extension.cs

示例9: ToBytes

        public static byte[] ToBytes(this BitArray array)
        {
            var messageBytes = new byte[array.Count];
            array.CopyTo(messageBytes, 0);

            return messageBytes;
        }
开发者ID:Rybzor,项目名称:Stego,代码行数:7,代码来源:BitArrayExtensions.cs

示例10: AsRandomAccessStream

 public static IRandomAccessStream AsRandomAccessStream( this Stream stream )
 {
     var randomAccessStream = new InMemoryRandomAccessStream();
     var s = randomAccessStream.AsStreamForWrite();
     stream.CopyTo(s);
     return randomAccessStream;
 }
开发者ID:kaorun55,项目名称:KinectService,代码行数:7,代码来源:MicrosoftStreamExtensions.cs

示例11: WriteToFile

 public static void WriteToFile(this Stream stream, string filePath)
 {
     using (var sw = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         stream.CopyTo(sw);
     }
 }
开发者ID:nyxiscoo1,项目名称:LearnMVC,代码行数:7,代码来源:StreamExtensions.cs

示例12: ToInteger

 public static int ToInteger(this BitArray bits)
 {
     var number = new int[1];
     bits.CopyTo(number, 0);
     var numberValue = number[0];
     return numberValue;
 }
开发者ID:RobertCPhillips,项目名称:CourseraAlgorithms,代码行数:7,代码来源:BitArrayExtensions.cs

示例13: AsBytes

 public static byte[] AsBytes(this Stream stream)
 {
     using (MemoryStream ms = new MemoryStream ()) {
         stream.CopyTo (ms);
         return ms.ToArray ();
     }
 }
开发者ID:benoitjadinon,项目名称:BlueMarin,代码行数:7,代码来源:StreamExtensions.cs

示例14: CopyStream

 /// <summary>
 /// Copies the stream.
 /// </summary>
 /// <param name="sourceStream">The source stream.</param>
 /// <param name="destinationStream">The destination stream.</param>
 public static void CopyStream(this Stream sourceStream, Stream destinationStream)
 {
     if (sourceStream != null && destinationStream != null)
     {
         sourceStream.CopyTo(destinationStream);
     }
 }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:12,代码来源:IOExtension.cs

示例15: Append

 /// <summary>
 ///     将一个BitArray拼接在当前对象之后
 /// </summary>
 /// <param name="current"></param>
 /// <param name="after"></param>
 /// <returns></returns>
 public static BitArray Append(this BitArray current, BitArray after)
 {
     var bools = new bool[current.Length + after.Length];
     current.CopyTo(bools, 0);
     after.CopyTo(bools, current.Length);
     return new BitArray(bools);
 }
开发者ID:UlyssesWu,项目名称:Encryption,代码行数:13,代码来源:BitArrayEx.cs


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