当前位置: 首页>>代码示例>>C#>>正文


C# IMessageSerializer.Deserialize方法代码示例

本文整理汇总了C#中IMessageSerializer.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageSerializer.Deserialize方法的具体用法?C# IMessageSerializer.Deserialize怎么用?C# IMessageSerializer.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessageSerializer的用法示例。


在下文中一共展示了IMessageSerializer.Deserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Time

        private void Time(IMessage[] messages, IMessageSerializer serializer) {
            Stopwatch watch = new Stopwatch();
            watch.Start();

            for (int i = 0; i < numberOfIterations; i++)
                using (MemoryStream stream = new MemoryStream())
                    serializer.Serialize(messages, stream);

            watch.Stop();
            Debug.WriteLine("Serializing: " + watch.Elapsed);

            watch.Reset();

            MemoryStream s = new MemoryStream();
            serializer.Serialize(messages, s);
            byte[] buffer = s.GetBuffer();
            s.Dispose();
            Console.WriteLine(Encoding.ASCII.GetString(buffer));

            watch.Start();

            object[] result = null;

            for (int i = 0; i < numberOfIterations; i++)
                using (var forDeserializing = new MemoryStream(buffer))
                    result = serializer.Deserialize(forDeserializing);

            watch.Stop();
            Debug.WriteLine("Deserializing: " + watch.Elapsed);
        }
开发者ID:jdaigle,项目名称:CWServiceBus,代码行数:30,代码来源:NamespaceTests.cs

示例2: Reserialize

        internal static object Reserialize(IMessageSerializer serializer, object message)
        {
            if (serializer == null)
                return message;

            var writer = new BinaryTokenStreamWriter();
            serializer.Serialize(message, writer);

            var bytes = writer.ToByteArray();
            var reader = new BinaryTokenStreamReader(bytes);

            return serializer.Deserialize(reader);
        }
开发者ID:rikace,项目名称:Orleankka,代码行数:13,代码来源:OrleansSerialization.cs

示例3: InvokeMutators

        private IMessage InvokeMutators(IMessage message, IMessageSerializer serializer)
        {
            var messageToSerialize = messageMutator.MutateOutgoing(message);
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(new[] { messageToSerialize }, stream);

                stream.Position = 0;

                var result = serializer.Deserialize(stream)[0];

                return messageMutator.MutateIncoming(result);
            }
        }
开发者ID:Rationalle,项目名称:NServiceBus,代码行数:14,代码来源:IntegrationTests.cs

示例4: ListenForMessages

        IObservable<object> ListenForMessages(ZmqContext context, string address, IMessageSerializer serializer)
        {
            return
                Observable.Create<object>
                (
                    o =>
                    {
                        _socket.Connect(address);

                        var poller = _scheduler.SchedulePeriodic
                        (
                            _pollInterval,
                            () =>
                            {
                                try
                                {
                                    var msg = _socket.ReceiveMessage(TimeSpan.Zero);
                                    while (msg != null && msg.FrameCount == 3)
                                    {
                                        var typeName = ZmqContext.DefaultEncoding.GetString(msg[1].Buffer);
                                        var type     = MessageTypeRegistry.Resolve(typeName);
                                        var data     = msg[2].Buffer;

                                        if (type != null)
                                        {
                                            var poco = serializer.Deserialize(data, type);
                                            o.OnNext(poco);
                                        }

                                        msg = _socket.ReceiveMessage(TimeSpan.Zero);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    o.OnError(ex);
                                }
                            }
                        );

                        return new CompositeDisposable(poller, Disposable.Create(() => _socket.Disconnect(address)));
                    }
                )
                .SubscribeOn(_scheduler)
                .ObserveOn(_scheduler)
                .Publish()
                .RefCount();
        }
开发者ID:xpando,项目名称:GrapevineZMQ,代码行数:47,代码来源:GrapevineReceiver.cs


注:本文中的IMessageSerializer.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。