Partager via


BodyWriter.CreateBufferedCopy(Int32) Méthode

Définition

Crée une copie mise en mémoire tampon du corps.

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

Paramètres

maxBufferSize
Int32

Taille maximale de la mémoire tampon pour le corps.

Retours

BodyWriter qui contient une copie de cet objet.

Exceptions

maxBufferSize est inférieure à zéro.

Le corps a déjà été écrit et ne peut plus être écrit ou l'enregistreur de corps n'est pas mis en mémoire tampon.

Exemples

L'exemple suivant indique comment créer une copie mise en mémoire tampon d'une instance BodyWriter existante.

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)

Remarques

Si l'objet IsBuffered a la valeur true alors l'objet BodyWriter est retourné. Si IsBuffered a la valeur false alors le contenu de BodyWriter jusqu'à maxBufferSize est retourné. Cela appelle également OnCreateBufferedCopy(Int32) en tant que point d'extensibilité.

S’applique à