Jurassic.Library.ObjectInstance.SetPropertyValue C# (CSharp) Method

SetPropertyValue() public method

Sets the value of the property with the given name. If a property with the given name does not exist, or exists in the prototype chain (and is not a setter) then a new property is created.
public SetPropertyValue ( object key, object value, bool throwOnError ) : void
key object The property key of the property to set.
value object The value to set the property to. This must be a javascript /// primitive (double, string, etc) or a class derived from .
throwOnError bool true to throw an exception if the property could not /// be set (i.e. if the property is read-only or if the object is not extensible and a new /// property needs to be created).
return void
        public void SetPropertyValue(object key, object value, bool throwOnError)
        {
            // Check if the property is an indexed property.
            uint arrayIndex = ArrayInstance.ParseArrayIndex(key);
            if (arrayIndex != uint.MaxValue)
            {
                SetPropertyValue(arrayIndex, value, throwOnError);
                return;
            }

            bool exists = SetPropertyValueIfExists(key, value, throwOnError);
            if (exists == false)
            {
                // The property doesn't exist - add it.
                AddProperty(key, value, PropertyAttributes.FullAccess, throwOnError);
            }
        }

Same methods

ObjectInstance::SetPropertyValue ( uint index, object value, bool throwOnError ) : void

Usage Example

示例#1
0
        public static ObjectInstance Assign(ScriptEngine engine, ObjectInstance target, params object[] sources)
        {
            foreach (var rawSource in sources)
            {
                // Ignore undefined or null sources.
                if (rawSource == null || rawSource == Undefined.Value || rawSource == Null.Value)
                    continue;
                var source = TypeConverter.ToObject(engine, rawSource);

                // Copy the enumerable properties from the source object.
                foreach (var property in source.Properties)
                    if (property.IsEnumerable == true)
                        target.SetPropertyValue(property.Key, property.Value, throwOnError: true);
            }
            return target;
        }
All Usage Examples Of Jurassic.Library.ObjectInstance::SetPropertyValue