當前位置: 首頁>>代碼示例>>C#>>正文


C# BsonWriter.Close方法代碼示例

本文整理匯總了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;
        }
開發者ID:intech,項目名稱:Checker,代碼行數:28,代碼來源:ThreadProcess.cs

示例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();
     }
 }
開發者ID:holajan,項目名稱:dotvvm,代碼行數:10,代碼來源:ViewModelProtectionHelper.cs

示例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);
        }
開發者ID:b-bot-108,項目名稱:brain-bot-111-b-bot-110-BND,代碼行數:16,代碼來源:BsonWriterTests.cs

示例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();
     }
 }
開發者ID:intech,項目名稱:Checker,代碼行數:10,代碼來源:CommandReader.cs


注:本文中的Newtonsoft.Json.Bson.BsonWriter.Close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。