本文介绍了净StreamWriter.BaseStream,这是什么的定义是什么意思? "获取底层流与后备存储接口和QUOT。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读关于的StreamWriter 的今天,遇到了这个属性, BaseStream

I was reading about StreamWriter today, and came across this property, BaseStream.

我一直在寻找一个定义,发现这个

I was looking for a definition and found this

获取底层流与后备存储接口。

从这里 MSDN - StreamWriter.BaseStream

我明白什么是BaseStream是StreamReader的,因为它的定义很简单:

I understand what a BaseStream is for StreamReader, because it's definition is very simply:

返回底层流。

但到底是什么的StreamWriter.BaseStream的定义是指?或者更清楚,是什么这部分的定义是指接口与后备存储?这听起来像废话给我。

But what does the definition of the StreamWriter.BaseStream mean?? Or more clearly, what does this part of the definition mean "interfaces with a backing store"? That sounds like gibberish to me.

推荐答案

你是对的;它似乎不必要的罗嗦,特别是在与类似的 StreamReader.BaseStream 比较。在现实中,它只是返回一个引用底层流,酷似的StreamReader。

You're right; it does seem unnecessarily wordy, especially in comparison with the analogous StreamReader.BaseStream. In reality, it just returns a reference to the underlying stream, exactly like StreamReader.

我想说明的presumption是写入底层流将涉及写入的数据保存到某种持久性存储,如文件。当然,这是没有必要的在现实中(在最坏的情况下,它可以简单地什么也不做)。

I think the presumption of the description is that writing to the underlying stream will involve saving the written data to some sort of persistent store, such as a file. Of course, this isn't necessary at all in reality (in the worst case, it could simply do nothing).

如果您的真正的要举一反三,你可以跨preT,由于这意味着底层流的 CanWrite 属性(至少在它被连接到StreamWriter的点)。

If you really wanted to extrapolate, you could interpret that as meaning that the underlying stream's CanWrite property is true (at least at the point it was attached to the StreamWriter).

要确信它真的只是返回底层流,这里是从反射器的反编译code:

To be convinced that it really is just returning the underlying stream, here's the decompiled code from Reflector:

public virtual Stream BaseStream
{
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    get
    {
        return this.stream;
    }
}

其中字段是初始化方法分配:

private void Init(Stream stream, Encoding encoding, int bufferSize)
{
    this.stream = stream;
   ...

这又被称为与参数的构造是在连接的流:

[SecuritySafeCritical]
public StreamWriter(Stream stream, Encoding encoding, int bufferSize) 
  : base(null)
{
    ...
    this.Init(stream, encoding, bufferSize);
}

这篇关于净StreamWriter.BaseStream,这是什么的定义是什么意思? "获取底层流与后备存储接口和QUOT。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 14:12