private void Initialise()
        {
            IRegistry reg = new Registry();

            reg.Add(RegistryResolver, new RegistryResolver(reg));

            ParameterRegistry.Add(ValueIdentifier, reg);
        }
Beispiel #2
0
        /// <summary>
        /// Create a command that sets multiple registry kess to multiple different values.
        /// Both arrays may not be <c>null</c>, nor empty, nor differ in length.
        /// </summary>
        /// <param name="keys">The registry keys that will be modified. They have to be fully resolved.</param>
        /// <param name="values">The values that will be set to the registry. The first key will receive the first value and so on.</param>
        /// <param name="onFinish">The function that will be called when the execution has been finished. If <c>null</c>, no function will be called.</param>
        public SetValueCommand(string[] keys, T[] values, Action onFinish = null) : base(onFinish, keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (keys.Length == 0)
            {
                throw new ArgumentException("Value cannot be an empty collection.", nameof(keys));
            }
            if (values.Length == 0)
            {
                throw new ArgumentException("Value cannot be an empty collection.", nameof(values));
            }


            // if there is only one value, all keys will receive this value
            // if the lengths are different, we don't know what to do
            if (values.Length != 1 && keys.Length != values.Length)
            {
                throw new ArgumentException($"{nameof(keys)} and {nameof(values)} have different lengths.", nameof(keys));
            }

            // set default values
            AddItentifierIfNotExists = false;

            // expand the values
            if (values.Length == 1 && keys.Length != 1)
            {
                T[] expandedValues = new T[keys.Length];
                for (int i = 0; i < expandedValues.Length; i++)
                {
                    expandedValues[i] = values[0];
                }

                values = expandedValues;
            }

            //store keys and values in the parameter registry
            ParameterRegistry.Add(KeyIdentifier, keys);
            ParameterRegistry.Add(ValueIdentifier, values);
        }