public static XmlDictionaryWriter CreateJsonWriter(Stream stream, Encoding encoding, bool ownsStream, bool indent, string?indentChars)
        {
            XmlJsonWriter writer = new XmlJsonWriter(indent, indentChars);

            writer.SetOutput(stream, encoding, ownsStream);
            return(writer);
        }
Exemplo n.º 2
0
        public static XmlDictionaryWriter CreateJsonWriter(Stream stream, Encoding encoding, bool ownsStream)
        {
            XmlJsonWriter writer = new XmlJsonWriter();

            writer.SetOutput(stream, encoding, ownsStream);
            return(writer);
        }
 internal static bool CheckIfJsonNameRequiresMapping(string jsonName)
 {
     if (jsonName != null)
     {
         if (!DataContract.IsValidNCName(jsonName))
         {
             return(true);
         }
         for (int i = 0; i < jsonName.Length; i++)
         {
             if (XmlJsonWriter.CharacterNeedsEscaping(jsonName[i]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        static XElement AddSampleJson(XElement content, string title, string label)
        {
            StringBuilder sample = new StringBuilder();

            using (MemoryStream stream = new MemoryStream())
            {
                using (XmlJsonWriter writer = new XmlJsonWriter())
                {
                    writer.SetOutput(stream, Encoding.Unicode, false);
                    content.WriteTo(writer);
                }
                stream.Position = 0;
                sample.Append(new StreamReader(stream, Encoding.Unicode).ReadToEnd());
            }
            int  depth    = 0;
            bool inString = false;

            for (int i = 0; i < sample.Length; ++i)
            {
                if (sample[i] == '"')
                {
                    inString = !inString;
                }
                else if (sample[i] == '{')
                {
                    sample.Insert(i + 1, "\n" + new String('\t', ++depth));
                    i += depth + 1;
                }
                else if (sample[i] == ',' && !inString)
                {
                    sample.Insert(i + 1, "\n" + new String('\t', depth));
                }
                else if (sample[i] == '}' && depth > 0)
                {
                    sample.Insert(i, "\n" + new String('\t', --depth));
                    i += depth + 1;
                }
            }
            return(AddSample(sample.ToString(), title, label));
        }