共用方式為


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,則會傳回最大為 BodyWritermaxBufferSize 內容。 這也會呼叫 OnCreateBufferedCopy(Int32) 當做擴充點。

適用於