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">
        /// Indicates the number of space characters to use as white space;
        /// this number is capped at 10 (if it is greater, the value is just 10).
        /// Values less than 1 indicate that no space should be used.
        /// </param>
        /// <param name="json">
        /// When the method returns, the JSON string representing this <see cref="JSValue"/>.
        /// </param>
        /// <returns>true if the operation is successful; otherwise, false.</returns>
        public bool TryGetJSON(QuickJSValue replacer, int space, out string json)
        {
            if (replacer is null)
            {
                return(NativeInstance.TryGetJSON(Context.NativeInstance, JSValue.Undefined, space, out json));
            }

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

            return(NativeInstance.TryGetJSON(Context.NativeInstance, replacer.NativeInstance, space, out json));
        }
Exemple #2
0
 /// <summary>
 /// Converts a JavaScript object or value to a JSON string.
 /// </summary>
 /// <param name="json">
 /// When the method returns, the JSON string representing this <see cref="JSValue"/>.
 /// </param>
 /// <returns>true if the operation is successful; otherwise, false.</returns>
 public bool TryGetJSON(out string json)
 {
     return(NativeInstance.TryGetJSON(Context.NativeInstance, out json));
 }