BodyWriter.CreateBufferedCopy(Int32) 方法

定义

创建正文的缓冲副本。

public:
 System::ServiceModel::Channels::BodyWriter ^ CreateBufferedCopy(int maxBufferSize);
public System.ServiceModel.Channels.BodyWriter CreateBufferedCopy (int maxBufferSize);
member this.CreateBufferedCopy : int -> System.ServiceModel.Channels.BodyWriter
Public Function CreateBufferedCopy (maxBufferSize As Integer) As BodyWriter

参数

maxBufferSize
Int32

正文缓冲区的最大大小。

返回

一个 BodyWriter,包含此对象的副本。

例外

maxBufferSize 小于零。

已写入正文且无法再次写入,或者未缓冲正文编写器。

示例

下面的示例演示如何创建现有 BodyWriter 实例的缓冲副本。

string[] strings = { "Hello", "world" };
MyBodyWriter bodyWriter = new MyBodyWriter(strings);

StringBuilder strBuilder = new StringBuilder(10);
XmlWriter writer = XmlWriter.Create(strBuilder);
XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);

bodyWriter.WriteBodyContents(dictionaryWriter);
dictionaryWriter.Flush();

MyBodyWriter bufferedBodyWriter = (MyBodyWriter) bodyWriter.CreateBufferedCopy(1024);
Dim strings() As String = {"Hello", "world"}
Dim bodyWriter As New MyBodyWriter(strings)

Dim strBuilder As New StringBuilder(10)
Dim writer As XmlWriter = XmlWriter.Create(strBuilder)
Dim dictionaryWriter As XmlDictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer)

bodyWriter.WriteBodyContents(dictionaryWriter)
dictionaryWriter.Flush()

Dim bufferedBodyWriter As MyBodyWriter = CType(bodyWriter.CreateBufferedCopy(1024), MyBodyWriter)

注解

如果 IsBufferedtrue,则返回 BodyWriter 对象。 如果 IsBufferedfalse,则返回 BodyWriter 的最大大小为 maxBufferSize 的内容。 还将调用 OnCreateBufferedCopy(Int32) 作为可扩展点。

适用于