Пример #1
0
        /// <summary>
        /// A helper method for serializing an object to EcmaScript
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static new string Serialize(object value)
        {
            StringBuilder output = new StringBuilder();

            using (EcmaScriptWriter writer = new EcmaScriptWriter(output))
            {
                writer.Write(value);
            }

            return(output.ToString());
        }
Пример #2
0
        protected override void Write(object value, bool isProperty, Type fieldType = null)
        {
            if (value is Regex)
            {
                if (isProperty && this.Settings.PrettyPrint)
                {
                    this.TextWriter.Write(' ');
                }
                EcmaScriptWriter.WriteEcmaScriptRegExp(this, (Regex)value);
                return;
            }

            base.Write(value, isProperty);
        }
Пример #3
0
 /// <summary>
 /// Outputs a .NET Regex as an ECMAScript RegExp literal.
 /// Defaults to global matching off.
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="regex"></param>
 /// <remarks>
 /// http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
 /// </remarks>
 public static void WriteEcmaScriptRegExp(JsonWriter writer, Regex regex)
 {
     EcmaScriptWriter.WriteEcmaScriptRegExp(writer, regex, false);
 }
Пример #4
0
 /// <summary>
 /// Writes dates as ECMAScript Date constructors
 /// </summary>
 /// <param name="value"></param>
 public override void Write(DateTime value)
 {
     EcmaScriptWriter.WriteEcmaScriptDate(this, value);
 }
Пример #5
0
        /// <summary>
        /// A helper method for serializing an object to EcmaScript
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static new string Serialize(object value)
        {
            StringBuilder output = new StringBuilder();

            using (EcmaScriptWriter writer = new EcmaScriptWriter(output))
            {
                writer.Write(value);
            }

            return output.ToString();
        }