Beispiel #1
0
        /// <summary>
        /// Appends a javascript property to the end of the collection that represents the specified propery name and value.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">A string that represents the value of the JSObjectItem to add to the end of the collection.</param>
        /// <param name="valueType">Type of the value.</param>
        /// <exception cref="System.ArgumentException">This will be thrown if the collection already contains the key.</exception>
        /// <exception cref="System.ArgumentException">
        /// This is thrown if the <em>type</em> is Method or ObjectLiteral.
        /// </exception>
        public void AddProperty(string propertyName, string value, JSObjectItemType type)
        {
            if (ContainsName(propertyName))
            {
                throw new ArgumentException("This collection already contains the name " + propertyName);
            }

            _items.Add(JSObjectItem.CreateProperty(propertyName, value, type));
        }
Beispiel #2
0
        /// <summary>
        /// Checks to see if this JSObjectItem contains a JSObjectItem with the property name, <em>propertyName</em>
        /// and is of JSObjectItemType, <em>type</em>.
        /// </summary>
        /// <param name="propertyName">The property name to look for.</param>
        /// <param name="type">The type of the property.</param>
        /// <returns>true if the collection contains a JSObjectProperty with the property name, <em>propertyName</em>
        /// and is of JSObjectItemType, <em>type</em>, false if it does not.</returns>
        public bool ContainsProperty(string propertyName, JSObjectItemType type)
        {
            int index = GetIndexOfName(propertyName);

            if (index == -1)
            {
                return(false);
            }

            JSObjectItem item = _items[index];

            return(item.ValueType == type);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new JSObjectItem of the type specified by <em>type</em>.
        /// </summary>
        /// <param name="propertyName">The name of the property to be created.</param>
        /// <param name="value">The value of the property.</param>
        /// <param name="type">The type of the property.</param>
        /// <returns>
        /// A JSObjectItem of the type specified by <em>type</em>.
        /// </returns>
        /// <remarks>
        /// This method cannot be used to create methods or ObjectLiteral properties.
        /// </remarks>
        /// <exception cref="System.ArgumentException">
        /// This is thrown if the <em>type</em> is Method or ObjectLiteral.
        /// </exception>
        public static JSObjectItem CreateProperty(string propertyName, string value, JSObjectItemType type)
        {
            JSObjectItem item = null;

            switch (type)
            {
            case JSObjectItemType.Bool:
                item = (JSObjectItem) new JSObjectBoolProperty(propertyName);
                break;

            case JSObjectItemType.Float:
                item = (JSObjectItem) new JSObjectFloatProperty(propertyName);
                break;

            case JSObjectItemType.Reference:
                item = (JSObjectItem) new JSObjectReferenceProperty(propertyName);
                break;

            case JSObjectItemType.Int:
                item = (JSObjectItem) new JSObjectIntProperty(propertyName);
                break;

            case JSObjectItemType.String:
                item = (JSObjectItem) new JSObjectStringProperty(propertyName);
                break;

            case JSObjectItemType.ObjectLiteral:
                throw new ArgumentException("Property type ObjectLiteral cannot be created by this function.");

            case JSObjectItemType.Method:
                throw new ArgumentException("Methods cannot be created by this function.");
            }

            item.StringValue = value;
            return(item);
        }