當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。