Beispiel #1
0
        /// <summary>
        /// Updates the value of a trigger property in this object's <see cref="Parameters"/>. If the trigger property does not exist, it will be added.
        /// </summary>
        /// <param name="property">The property whose value will be updated.</param>
        /// <param name="value">The value to insert.</param>
        /// <param name="requireValue">Indicates whether null is allowed for the specified property.</param>
        protected void UpdateCustomParameter(TriggerProperty property, object value, bool requireValue = false)
        {
            if (value == null && requireValue && Action != ModifyAction.Edit)
            {
                throw new InvalidOperationException($"Trigger property '{property}' cannot be null for trigger type '{Type}'");
            }

            var name      = $"{property.GetDescription()}_{this.subId}";
            var parameter = new CustomParameter(name, value);

            var index = GetCustomParameterIndex(property);

            if (index == -1)
            {
                Parameters.Add(parameter);
            }
            else
            {
                if (value == null)
                {
                    Parameters.RemoveAt(index);
                }
                else
                {
                    Parameters[index] = parameter;
                }
            }
        }
Beispiel #2
0
        private int GetCustomParameterIndex(TriggerProperty property)
        {
            var index = Parameters.FindIndex(a => a.Name.StartsWith(property.GetDescription()));

            return(index);
        }