/// <summary> /// Add a property to this JSObject with the provided name. The provided action will be invoked to populate the value of this property. /// </summary> /// <param name="propertyName">The name of the new property.</param> /// <param name="propertyValueAction">The action to invoke to add the property's value.</param> public void Property(string propertyName, Action <JSValue> propertyValueAction) { if (!string.IsNullOrEmpty(propertyBeingConstructed)) { throw new InvalidOperationException($"Cannot add a property to a JSObject while constructing its child property (\"{propertyBeingConstructed}\")."); } SetCurrentState(State.Property); if (PropertyNameNeedsToBeQuoted(propertyName)) { builder.QuotedString(propertyName); } else { builder.Text(propertyName); } builder.Text(": "); propertyBeingConstructed = propertyName; try { builder.Value(propertyValueAction); } finally { propertyBeingConstructed = null; } propertyNames.Add(propertyName); }
/// <summary> /// Add a quoted-string to this TSValue. /// </summary> /// <param name="text">The text to quote and add.</param> public virtual void QuotedString(string text) { builder.QuotedString(text); }