本文整理汇总了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;
}
示例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);
}
示例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");
}
示例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 ());
}