Exemple #1
0
        /// <summary>
        /// Converts a JavaScript object or value to a JSON string, optionally replacing values if
        /// a <paramref name="replacer"/> function is specified or optionally including only
        /// the specified properties if a <paramref name="replacer"/> array is specified.
        /// </summary>
        /// <param name="replacer">
        /// A function that alters the behavior of the stringification process, or an array of String
        /// and Number that serve as a whitelist for selecting/filtering the properties of the value
        /// object to be included in the JSON string.<para/>
        /// If this value is null or not provided, all properties of the object are included in the
        /// resulting JSON string.
        /// </param>
        /// <param name="space">
        /// The string (or the first 10 characters of the string, if it&apos;s longer than that)
        /// is used as white space. If this parameter is null, no white space is used.
        /// </param>
        /// <returns>The JSON string representing this <see cref="JSValue"/>.</returns>
        public string ToJSON(QuickJSValue replacer, string space)
        {
            if (replacer is null)
            {
                return(NativeInstance.ToJSON(Context.NativeInstance, JSValue.Undefined, space));
            }

            if (!Context.IsCompatibleWith(replacer.Context))
            {
                throw new ArgumentOutOfRangeException(nameof(replacer));
            }

            return(NativeInstance.ToJSON(Context.NativeInstance, replacer.NativeInstance, space));
        }
Exemple #2
0
 /// <summary>
 /// Converts a JavaScript object or value to a JSON string.
 /// </summary>
 /// <returns>The JSON string representing this <see cref="JSValue"/>.</returns>
 public string ToJSON()
 {
     return(NativeInstance.ToJSON(Context.NativeInstance));
 }