Ejemplo n.º 1
0
        private static TestsHelper.NodeInfo[] CreateDeserializationInfo(ListNode node)
        {
            var list = new List <TestsHelper.NodeInfo>();

            while (node != null)
            {
                var nodeInfo = new TestsHelper.NodeInfo
                {
                    RandomId = node.FindRandomNodeOffset(),
                    Data     = node.Data.DeepCopy()
                };
                list.Add(nodeInfo);
                node = node.Next;
            }

            return(list.ToArray());
        }
        private static SerializeDelegate SerializeFactory(StreamWriter writer)
        {
            var jsonSettings = new JsonSerializerSettings {
                DefaultValueHandling = DefaultValueHandling.Ignore
            };

            Task Serialize(int?randomId = null, in string data = null)
            {
                var node = new TestsHelper.NodeInfo {
                    RandomId = randomId, Data = data
                };
                var json = JsonConvert.SerializeObject(node, Formatting.None, jsonSettings);

                return(writer.WriteLineAsync(json == "{}" ? string.Empty : json));
            }

            return(Serialize);
        }