private static string ObjectToJSString(object o) { if (o == null) { return("null"); } if (o is string) { return(34.ToString() + o.ToString().Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\n", "\\n").Replace("\r", "\\r").Replace("\0", string.Empty).Replace("\x2028", string.Empty).Replace("\x2029", string.Empty) + (object)'"'); } if (o is int || o is short || (o is uint || o is ushort) || o is byte) { return(o.ToString()); } if (o is float) { NumberFormatInfo numberFormat = CultureInfo.InvariantCulture.NumberFormat; return(((float)o).ToString((IFormatProvider)numberFormat)); } if (o is double) { NumberFormatInfo numberFormat = CultureInfo.InvariantCulture.NumberFormat; return(((double)o).ToString((IFormatProvider)numberFormat)); } if (o is char) { if ((int)(char)o == 34) { return("\"\\\"\""); } return(34.ToString() + o.ToString() + (object)'"'); } if (!(o is IList)) { return(Application.ObjectToJSString((object)o.ToString())); } IList list = (IList)o; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("new Array("); int count = list.Count; for (int index = 0; index < count; ++index) { if (index != 0) { stringBuilder.Append(", "); } stringBuilder.Append(Application.ObjectToJSString(list[index])); } stringBuilder.Append(")"); return(stringBuilder.ToString()); }
private static string BuildInvocationForArguments(string functionName, params object[] args) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(functionName); stringBuilder.Append('('); int num = args.Length; for (int i = 0; i < num; i++) { if (i != 0) { stringBuilder.Append(", "); } stringBuilder.Append(Application.ObjectToJSString(args[i])); } stringBuilder.Append(')'); stringBuilder.Append(';'); return(stringBuilder.ToString()); }
private static string ObjectToJSString(object o) { string result; if (o == null) { result = "null"; } else if (o is string) { string text = o.ToString().Replace("\\", "\\\\"); text = text.Replace("\"", "\\\""); text = text.Replace("\n", "\\n"); text = text.Replace("\r", "\\r"); text = text.Replace("\0", ""); text = text.Replace("\u2028", ""); text = text.Replace("\u2029", ""); result = '"' + text + '"'; } else if (o is int || o is short || o is uint || o is ushort || o is byte) { result = o.ToString(); } else if (o is float) { NumberFormatInfo numberFormat = CultureInfo.InvariantCulture.NumberFormat; result = ((float)o).ToString(numberFormat); } else if (o is double) { NumberFormatInfo numberFormat2 = CultureInfo.InvariantCulture.NumberFormat; result = ((double)o).ToString(numberFormat2); } else if (o is char) { if ((char)o == '"') { result = "\"\\\"\""; } else { result = '"' + o.ToString() + '"'; } } else if (o is IList) { IList list = (IList)o; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("new Array("); int count = list.Count; for (int i = 0; i < count; i++) { if (i != 0) { stringBuilder.Append(", "); } stringBuilder.Append(Application.ObjectToJSString(list[i])); } stringBuilder.Append(")"); result = stringBuilder.ToString(); } else { result = Application.ObjectToJSString(o.ToString()); } return(result); }
private static string ObjectToJSString(object o) { bool flag = o == null; string result; if (flag) { result = "null"; } else { bool flag2 = o is string; if (flag2) { string text = o.ToString().Replace("\\", "\\\\"); text = text.Replace("\"", "\\\""); text = text.Replace("\n", "\\n"); text = text.Replace("\r", "\\r"); text = text.Replace("\0", ""); text = text.Replace("\u2028", ""); text = text.Replace("\u2029", ""); result = "\"" + text + "\""; } else { bool flag3 = o is int || o is short || o is uint || o is ushort || o is byte; if (flag3) { result = o.ToString(); } else { bool flag4 = o is float; if (flag4) { NumberFormatInfo numberFormat = CultureInfo.InvariantCulture.NumberFormat; result = ((float)o).ToString(numberFormat); } else { bool flag5 = o is double; if (flag5) { NumberFormatInfo numberFormat2 = CultureInfo.InvariantCulture.NumberFormat; result = ((double)o).ToString(numberFormat2); } else { bool flag6 = o is char; if (flag6) { bool flag7 = (char)o == '"'; if (flag7) { result = "\"\\\"\""; } else { result = "\"" + o.ToString() + "\""; } } else { bool flag8 = o is IList; if (flag8) { IList list = (IList)o; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("new Array("); int count = list.Count; for (int i = 0; i < count; i++) { bool flag9 = i != 0; if (flag9) { stringBuilder.Append(", "); } stringBuilder.Append(Application.ObjectToJSString(list[i])); } stringBuilder.Append(")"); result = stringBuilder.ToString(); } else { result = Application.ObjectToJSString(o.ToString()); } } } } } } } return(result); }