public static string ToZinc(HaystackValue val)
 {
     using (var stream = new MemoryStream())
         using (var streamWriter = new StreamWriter(stream))
             using (var writer = new ZincWriter(streamWriter))
             {
                 writer.WriteValue(val);
                 streamWriter.Flush();
                 stream.Position = 0;
                 return(new StreamReader(stream).ReadToEnd());
             }
 }
        public void WriteEntity(HaystackDictionary entity)
        {
            if (isFirst)
            {
                isFirst = false;
            }
            else
            {
                _trioWriter.WriteLine("---");
            }

            foreach (var kv in entity)
            {
                if (kv.Value == null)
                {
                    continue;
                }
                _trioWriter.Write(kv.Key);
                if (kv.Value is HaystackMarker)
                {
                    _trioWriter.WriteLine();
                    continue;
                }
                _trioWriter.Write(":");
                if (kv.Value is HaystackGrid)
                {
                    _trioWriter.Write("Zinc:");
                    _trioWriter.WriteLine();
                    var val = ZincWriter.ToZinc(kv.Value);
                    foreach (var line in val.TrimEnd().Split(new[] { "\n" }, StringSplitOptions.None))
                    {
                        _trioWriter.Write("  ");
                        _trioWriter.WriteLine(line.TrimEnd());
                    }
                }
                else if (kv.Value is HaystackString stringValue && stringValue.Value.Contains("\n"))
                {
                    var val = stringValue.Value;
                    _trioWriter.WriteLine();
                    foreach (var line in val.TrimEnd().Split(new[] { "\n" }, StringSplitOptions.None))
                    {
                        _trioWriter.Write("  ");
                        _trioWriter.WriteLine(line.TrimEnd());
                    }
                }