本文整理汇总了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();
}
}