Пример #1
0
        public static string Serialize <T>(T obj)
        {
            var sw     = new StringWriter();
            var writer = new IonTextWriter(sw);
            var action = IonSerializerExpression.GetAction <T>();

            action(obj, writer);
            writer.Finish();
            return(sw.ToString());
        }
Пример #2
0
        public void Run(string[] args)
        {
            // var exp = typeof(IEnumerator).GetMethod(nameof(IEnumerator.MoveNext));
            // var exp2 = typeof(IValueWriter).GetMethod(nameof(IIonWriter.WriteString));
            // Console.WriteLine(exp);
            // Console.WriteLine(exp2);
            // return;

            //            var trueS = IonSerialization.Serialize(new Per
            //            {
            //                Name = "huy"
            //            });
            //            Console.WriteLine(string.Join(',', trueS.Select(b => $"{b:x2}")));
            var s = IonSerializerExpression.Serialize(new[]
            {
                new Experiment
                {
                    Name = "Boxing Perftest",
                    // Duration = TimeSpan.FromSeconds(90),
                    Id          = 233,
                    StartDate   = new DateTimeOffset(2018, 07, 21, 11, 11, 11, TimeSpan.Zero),
                    IsActive    = true,
                    Description = "Measure performance impact of boxing",
                    Result      = ExperimentResult.Failure,
                    SampleData  = new byte[100],
                    Budget      = decimal.Parse("12345.01234567890123456789"),
                    Outputs     = new[] { 1, 2, 3 }
                }
            });

            var s2 = IonSerializerExpression.Serialize(new[]
            {
                new Experiment
                {
                    Name = "Boxing Perftest",
                    // Duration = TimeSpan.FromSeconds(90),
                    Id          = 233,
                    StartDate   = new DateTimeOffset(2018, 07, 21, 11, 11, 11, TimeSpan.Zero),
                    IsActive    = true,
                    Description = "Measure performance impact of boxing",
                    Result      = ExperimentResult.Failure,
                    SampleData  = new byte[100],
                    Budget      = decimal.Parse("12345.01234567890123456789")
                }
            });
            //            Console.WriteLine(string.Join(',', s.Select(b => $"{b:x2}")));
            var d    = IonSerialization.Deserialize <Experiment[]>(s);
            var json = JsonConvert.SerializeObject(d, Formatting.Indented);

            Console.WriteLine(json);
        }
Пример #3
0
        public static byte[] Serialize <T>(T obj)
        {
            var action = IonSerializerExpression.GetAction <T>();

            // var action = GetAction<T>();
            //now write
            using (var stream = new MemoryStream())
            {
                var writer = new ManagedBinaryWriter(stream, Symbols.EmptySymbolTablesArray);
                action(obj, writer);
                writer.Flush();
                writer.Finish();
                return(stream.GetWrittenBuffer());
            }
        }