本文整理匯總了C#中Newtonsoft.Json.Bson.BsonWriter.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonWriter.Close方法的具體用法?C# BsonWriter.Close怎麽用?C# BsonWriter.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Newtonsoft.Json.Bson.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.Close方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SendCmdRequest
public bool SendCmdRequest(CmdRequest request)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Connect("127.0.0.1", Port);
using (NetworkStream stream = new NetworkStream(socket))
{
using (BsonWriter writer = new BsonWriter(stream))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(writer, request);
writer.Flush();
writer.Close();
}
stream.Close();
}
}
catch(Exception ex)
{
Logger.AddError(string.Format("Failed to send cmd request to checker with port = {0}", Port), ex);
return false;
}
return true;
}
示例2: Serialize
protected virtual byte[] Serialize(object obj)
{
using (var ms = new MemoryStream())
{
var bw = new BsonWriter(ms);
Serializer.Serialize(bw, obj);
bw.Close();
return ms.ToArray();
}
}
示例3: CloseOutput
public void CloseOutput()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
Assert.IsTrue(ms.CanRead);
writer.Close();
Assert.IsFalse(ms.CanRead);
ms = new MemoryStream();
writer = new BsonWriter(ms) { CloseOutput = false };
Assert.IsTrue(ms.CanRead);
writer.Close();
Assert.IsTrue(ms.CanRead);
}
示例4: WriteReply
private void WriteReply(NetworkStream stream, CmdServerReply reply)
{
JsonSerializer serializer = new JsonSerializer();
using (BsonWriter writer = new BsonWriter(stream))
{
serializer.Serialize(writer, reply);
writer.Flush();
writer.Close();
}
}