private static object Escape(object obj) { string str = obj as string; if (str != null) { obj = UnicodeUtil.EscapeInvalidSurrogates(str); } return(obj); }
private static object EscapeOrUnescape(object obj, bool escape) { string str = obj as string; if (str != null) { return(escape ? UnicodeUtil.EscapeInvalidSurrogates(str) : UnicodeUtil.UnescapeInvalidSurrogates(str)); } object[] arr = obj as object[]; if (arr != null) { for (int i = 0; i < arr.Length; i++) { arr[i] = EscapeOrUnescape(arr[i], escape); } } return(obj); }