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


C# Stream.GetType方法代码示例

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


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

示例1: StreamToBuffer

		internal static byte[] StreamToBuffer (Stream assemblyStream)
		{
			byte [] buffer;

			using (assemblyStream) {
				// avoid extra step for MemoryStream (but not any stream that inherits from it)
				if (assemblyStream.GetType () == MemoryStreamType)
					return (assemblyStream as MemoryStream).ToArray ();

				// it's normally bad to depend on Stream.Length since some stream (e.g. NetworkStream)
				// don't implement them. However it is safe in this case (i.e. SL2 depends on Length too)
				buffer = new byte [assemblyStream.Length];

				int length = buffer.Length;
				int offset = 0;
				while (length > 0) {
					int read = assemblyStream.Read (buffer, offset, length);
					if (read == 0)
						break;

					length -= read;
					offset += read;
				}
			}

			return buffer;
		}
开发者ID:dfr0,项目名称:moon,代码行数:27,代码来源:AssemblyPart.cs

示例2: IsFileStream

        internal static bool IsFileStream(Stream stream)
        {
            if (FileStreamType.Value == null)
            {
                return false;
            }

            var type = stream.GetType();
            return type == FileStreamType.Value || type.GetTypeInfo().IsSubclassOf(FileStreamType.Value);
        }
开发者ID:Dmitry-Me,项目名称:corefx,代码行数:10,代码来源:FileStreamReadLightUp.cs

示例3: BinaryReader

        public BinaryReader(Stream input, Encoding encoding, bool leaveOpen)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }
            if (!input.CanRead)
            {
                throw new ArgumentException(SR.Argument_StreamNotReadable);
            }

            _stream = input;
            _decoder = encoding.GetDecoder();
            _maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
            int minBufferSize = encoding.GetMaxByteCount(1);  // max bytes per one char
            if (minBufferSize < 16)
            {
                minBufferSize = 16;
            }

            _buffer = new byte[minBufferSize];
            // _charBuffer and _charBytes will be left null.

            // For Encodings that always use 2 bytes per char (or more), 
            // special case them here to make Read() & Peek() faster.
            _2BytesPerChar = encoding is UnicodeEncoding;
            // check if BinaryReader is based on MemoryStream, and keep this for it's life
            // we cannot use "as" operator, since derived classes are not allowed
            _isMemoryStream = (_stream.GetType() == typeof(MemoryStream));
            _leaveOpen = leaveOpen;

            Debug.Assert(_decoder != null, "[BinaryReader.ctor]_decoder!=null");
        }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:37,代码来源:BinaryReader.cs

示例4: GetSubStream

		// GetSubStream returns a 'copy' of the InputStream with Position set to 0.
		static Stream GetSubStream (Stream stream)
		{
#if !TARGET_JVM
			if (stream is IntPtrStream)
				return new IntPtrStream (stream);
#endif

			if (stream is MemoryStream) {
				MemoryStream other = (MemoryStream) stream;
				return new MemoryStream (other.GetBuffer (), 0, (int) other.Length, false, true);
			}

			if (stream is TempFileStream) {
				((TempFileStream) stream).SavePosition ();
				return stream;
			}

			throw new NotSupportedException ("The stream is " + stream.GetType ());
		}
开发者ID:frje,项目名称:SharpLang,代码行数:20,代码来源:HttpRequest.cs


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