BodyWriter.CreateBufferedCopy(Int32) Metodo

Definizione

Crea una copia del corpo memorizzata nel buffer.

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

Parametri

maxBufferSize
Int32

Dimensione massima del buffer per il corpo.

Restituisce

BodyWriter

BodyWriter contiene una copia di questo oggetto.

Eccezioni

maxBufferSize è minore di zero.

Il corpo è già stato scritto e non può essere scritto di nuovo, oppure il writer del corpo non è memorizzato nel buffer.

Esempio

Nell'esempio seguente viene illustrato come creare una copia memorizzata nel buffer di un'istanza BodyWriter esistente.

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)

Commenti

Se IsBuffered è true, verrà restituito l'oggetto BodyWriter. Se IsBuffered è false, verrà restituito il contenuto di BodyWriter fino a maxBufferSize. In tal modo viene chiamato anche OnCreateBufferedCopy(Int32) come punto di estendibilità.

Si applica a