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


C# BinaryTokenStreamWriter.ToByteArray方法代码示例

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


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

示例1: ILSerializer_AllowCopiedFieldsToDifferFromSerializedFields

        public void ILSerializer_AllowCopiedFieldsToDifferFromSerializedFields()
        {
            var input = new FieldTest
            {
                One = 1,
                Two = 2,
                Three = 3
            };

            var generator = new ILSerializerGenerator();
            var serializers = generator.GenerateSerializer(input.GetType(), f => f.Name != "One", f => f.Name != "Three");
            var copy = (FieldTest)serializers.DeepCopy(input);
            Assert.Equal(1, copy.One);
            Assert.Equal(2, copy.Two);
            Assert.Equal(0, copy.Three);

            var writer = new BinaryTokenStreamWriter();
            serializers.Serialize(input, writer, input.GetType());
            var reader = new BinaryTokenStreamReader(writer.ToByteArray());
            var deserialized = (FieldTest)serializers.Deserialize(input.GetType(), reader);

            Assert.Equal(0, deserialized.One);
            Assert.Equal(2, deserialized.Two);
            Assert.Equal(3, deserialized.Three);
        }
开发者ID:jdom,项目名称:orleans,代码行数:25,代码来源:ILBasedSerializerTests.cs

示例2: SerializeProperties

 /// <summary>
 /// Serializes event data properties
 /// </summary>
 /// <param name="eventData"></param>
 /// <returns></returns>
 public static byte[] SerializeProperties(this EventData eventData)
 {
     var writeStream = new BinaryTokenStreamWriter();
     SerializationManager.Serialize(eventData.Properties.Where(kvp => !SkipProperties.Contains(kvp.Key)).ToList(), writeStream);
     var result = writeStream.ToByteArray();
     writeStream.ReleaseBuffers();
     return result;
 }
开发者ID:jdom,项目名称:orleans,代码行数:13,代码来源:EventDataExtensions.cs

示例3: VerifyUsingFallbackSerializer

        public static void VerifyUsingFallbackSerializer(object ob)
        {
            var writer = new BinaryTokenStreamWriter();
            SerializationManager.FallbackSerializer(ob, writer, ob.GetType());
            var bytes = writer.ToByteArray();

            var reader = new BinaryTokenStreamReader(bytes);
            var serToken = reader.ReadToken();
            Assert.Equal(SerializationTokenType.Fallback, serToken);
        }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:10,代码来源:SerializationTestsUtils.cs

示例4: DeepCopy

        /// <summary>
        /// Creates a deep copy of an object
        /// </summary>
        /// <param name="source">The source object to be copy</param>
        /// <returns>The copy that was created</returns>
        public object DeepCopy(object source)
        {
            if (source == null)
            {
                return null;
            }

            var writer = new BinaryTokenStreamWriter();
            Serialize(source, writer, source.GetType());
            var retVal = Deserialize(source.GetType(), new BinaryTokenStreamReader(writer.ToByteArray()));
            return retVal;
        }
开发者ID:PaulNorth,项目名称:orleans,代码行数:17,代码来源:OrleansJsonSerializer.cs

示例5: EventSequenceTokenV2_Serialize_IfNotNull

 public void EventSequenceTokenV2_Serialize_IfNotNull()
 {
     var writer = new BinaryTokenStreamWriter();
     var token = new EventSequenceTokenV2(long.MaxValue, int.MaxValue);
     EventSequenceTokenV2.Serialize(token, writer, null);
     var reader = new BinaryTokenStreamReader(writer.ToByteArray());
     var deserialized = EventSequenceTokenV2.Deserialize(typeof(EventSequenceTokenV2), reader) as EventSequenceTokenV2;
     Assert.NotNull(deserialized);
     Assert.NotSame(token, deserialized);
     Assert.Equal(token.EventIndex, deserialized.EventIndex);
     Assert.Equal(token.SequenceNumber, deserialized.SequenceNumber);
 }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:12,代码来源:StreamTypeSerializationTests.cs

示例6: 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

示例7: AzureQueueBatchContainerV2_Serialize_IfNotNull

        public void AzureQueueBatchContainerV2_Serialize_IfNotNull()
        {
            var container = CreateAzureQueueBatchContainer();
            var writer = new BinaryTokenStreamWriter();
            AzureQueueBatchContainerV2.Serialize(container, writer, null);
            var reader = new BinaryTokenStreamReader(writer.ToByteArray());
            var deserialized = AzureQueueBatchContainerV2.Deserialize(typeof(AzureQueueBatchContainer), reader) as AzureQueueBatchContainerV2;
            ValidateIdenticalQueueBatchContainerButNotSame(container, deserialized);

            writer = new BinaryTokenStreamWriter();
            SerializationManager.Serialize(container, writer);
            reader = new BinaryTokenStreamReader(writer.ToByteArray());
            deserialized = SerializationManager.Deserialize<AzureQueueBatchContainerV2>(reader);
            ValidateIdenticalQueueBatchContainerButNotSame(container, deserialized);
        }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:15,代码来源:StreamTypeSerializationTests.cs

示例8: AzureQueueBatchContainer_VerifyBothMessageTypesCanBeDeserialized

        public void AzureQueueBatchContainer_VerifyBothMessageTypesCanBeDeserialized()
        {
            var container = new AzureQueueBatchContainer(Guid.NewGuid(), "namespace", new List<object> { "item" }, new Dictionary<string, object>() { { "key", "value" } }, new EventSequenceToken(long.MaxValue, int.MaxValue));
            var writer = new BinaryTokenStreamWriter();
            SerializationManager.Serialize(container, writer);
            var bytes = writer.ToByteArray();

            writer = new BinaryTokenStreamWriter();
            var container2 = new AzureQueueBatchContainerV2(Guid.NewGuid(), "namespace", new List<object> { "item" }, new Dictionary<string, object>() { { "key", "value" } }, new EventSequenceTokenV2(long.MaxValue, int.MaxValue));
            SerializationManager.Serialize(container2, writer);
            var bytes2 = writer.ToByteArray();

            var msg = new CloudQueueMessage(bytes);
            var msg2 = new CloudQueueMessage(bytes2);
            var bc1 = (IBatchContainer)AzureQueueBatchContainer.FromCloudQueueMessage(msg, 0);
            var bc2 = (IBatchContainer)AzureQueueBatchContainer.FromCloudQueueMessage(msg2, 0);
            Assert.NotNull(bc1);
            Assert.NotNull(bc2);
        }
开发者ID:amccool,项目名称:orleans,代码行数:19,代码来源:StreamTypeSerializationTests.cs

示例9: EventSequenceTokenV2_DeepCopy_IfNotNull

        public void EventSequenceTokenV2_DeepCopy_IfNotNull()
        {
            var token = new EventSequenceTokenV2(long.MaxValue, int.MaxValue);
            var copy = EventSequenceTokenV2.DeepCopy(token) as EventSequenceToken;
            Assert.NotNull(copy);
            Assert.NotSame(token, copy);
            Assert.Equal(token.EventIndex, copy.EventIndex);
            Assert.Equal(token.SequenceNumber, copy.SequenceNumber);

            var writer = new BinaryTokenStreamWriter();
            SerializationManager.Serialize(token, writer);
            var bytes = writer.ToByteArray();

            var reader = new BinaryTokenStreamReader(bytes);
            copy = SerializationManager.Deserialize(reader) as EventSequenceToken;
            Assert.NotNull(copy);
            Assert.NotSame(token, copy);
            Assert.Equal(token.EventIndex, copy.EventIndex);
            Assert.Equal(token.SequenceNumber, copy.SequenceNumber);
        }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:20,代码来源:StreamTypeSerializationTests.cs

示例10: VerifyUsingFallbackSerializer

        private static void VerifyUsingFallbackSerializer(object ob)
        {
            var writer = new BinaryTokenStreamWriter();
            SerializationManager.FallbackSerializer(ob, writer, ob.GetType());
            var bytes = writer.ToByteArray();

            byte[] defaultFormatterBytes;
            var formatter = new BinaryFormatter();
            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, ob);
                stream.Flush();
                defaultFormatterBytes = stream.ToArray();
            }

            var reader = new BinaryTokenStreamReader(bytes);
            var serToken = reader.ReadToken();
            Assert.Equal(SerializationTokenType.Fallback, serToken);
            var length = reader.ReadInt();
            Assert.Equal(length, defaultFormatterBytes.Length);
            var segment = new ArraySegment<byte>(bytes, reader.CurrentPosition, bytes.Length - reader.CurrentPosition);
            Assert.True(segment.SequenceEqual(defaultFormatterBytes));
        }
开发者ID:amccool,项目名称:orleans,代码行数:23,代码来源:StreamTypeSerializationTests.cs

示例11: GetTokenBytes

 private static byte[] GetTokenBytes(StreamSequenceToken token)
 {
     var bodyStream = new BinaryTokenStreamWriter();
     SerializationManager.Serialize(token, bodyStream);
     return bodyStream.ToByteArray();
 }
开发者ID:PaulNorth,项目名称:orleans,代码行数:6,代码来源:StreamDeliveryFailureEntity.cs

示例12: GetTokenBytes

 private static byte[] GetTokenBytes(StreamSequenceToken token)
 {
     var bodyStream = new BinaryTokenStreamWriter();
     SerializationManager.Serialize(token, bodyStream);
     var result = bodyStream.ToByteArray();
     bodyStream.ReleaseBuffers();
     return result;
 }
开发者ID:jdom,项目名称:orleans,代码行数:8,代码来源:StreamDeliveryFailureEntity.cs

示例13: SerializeProperties

 public static byte[] SerializeProperties(this IDictionary<string, object> properties)
 {
     var writeStream = new BinaryTokenStreamWriter();
     SerializationManager.Serialize(properties, writeStream);
     return writeStream.ToByteArray();
 }
开发者ID:Joshua-Ferguson,项目名称:orleans,代码行数:6,代码来源:EventDataExtensions.cs

示例14: SerializeProperties

 public static byte[] SerializeProperties(this IDictionary<string, object> properties)
 {
     var writeStream = new BinaryTokenStreamWriter();
     SerializationManager.Serialize(properties.Where(kvp => !SkipProperties.Contains(kvp.Key)).ToList(), writeStream);
     return writeStream.ToByteArray();
 }
开发者ID:caomw,项目名称:orleans,代码行数:6,代码来源:EventDataExtensions.cs


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