/// <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()); }
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); }
/// <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); }
/// <summary> /// Writes dates as ECMAScript Date constructors /// </summary> /// <param name="value"></param> public override void Write(DateTime value) { EcmaScriptWriter.WriteEcmaScriptDate(this, value); }
/// <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(); }