unsafe static int TrySerializer <T>(StringBuilder sb, params T[] samples)
        {
            int failures = 0;

            sb.AppendLine();
            sb.AppendLine("# " + SchemaTest.HumanName(typeof(T)));
            sb.AppendLine();

            var    emit = DelegateBuilder.CreateStream <T>(Schema.Reflect(typeof(T)));
            string instructions;
            var    del = (Serializer.WriteToStream <T>)emit.CreateDelegate(typeof(Serializer.WriteToStream <T>), out instructions);

            sb.AppendLine(emit.Instructions());
            sb.AppendLine();

            var ms     = new MemoryStream();
            var buffer = new byte[64];

            for (int i = 0; i < samples.Length; i++)
            {
                ms.Position = 0;
                fixed(byte *ptr = buffer)
                {
                    del.Invoke(ref samples[i], ptr, ms, buffer);
                }

                var newt = DelegateBuilderTest.GetNewtonsoft(samples[i]);
                var mine = ms.GetBuffer().Take((int)ms.Position);

                sb.AppendLine();
                sb.AppendLine("## Newtonsoft");
                Util.Hex.Dump(sb, newt);
                sb.AppendLine();

                sb.AppendLine();
                sb.AppendLine("## Cameronism.Json");
                Util.Hex.Dump(sb, mine);
                sb.AppendLine();
                sb.AppendLine();

                bool equal = newt.SequenceEqual(mine);
                sb.AppendLine("Equal: " + equal);
                sb.AppendLine();

                if (!equal)
                {
                    failures++;
                }
            }

            return(failures);
        }
Пример #2
0
 static int SerializeValues <T>(StringBuilder sb, byte[] buffer, bool approveIL, params T[] values)
 {
     return(DelegateBuilderTest.SerializeValues(sb, buffer, values, approveIL));
 }