Example #1
0
        /// <summary>
        /// Gets this setting's value as an array of a specific type.
        /// Note: this only works if the setting represents an array. If it is not, then null is returned.
        /// </summary>
        /// <param name="elementType">
        ///     The type of elements in the array. All values in the array are going to be converted to objects of this type.
        ///     If the conversion of an element fails, an exception is thrown.
        /// </param>
        /// <returns></returns>
        public object[] GetValueArray(Type elementType)
        {
            int myArraySize = this.ArraySize;

            if (myArraySize < 0)
            {
                return(null);
            }

            var values = new object[myArraySize];

            if (myArraySize > 0)
            {
                var enumerator = new SettingArrayEnumerator(mRawValue);

                while (enumerator.Next())
                {
                    values[enumerator.Index] = CreateObjectFromString(enumerator.Current, elementType);
                }
            }

            return(values);
        }
Example #2
0
        /// <summary>
        /// Gets this setting's value as an array of a specific type.
        /// Note: this only works if the setting represents an array. If it is not, then null is returned.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of elements in the array. All values in the array are going to be converted to objects of this type.
        ///     If the conversion of an element fails, an exception is thrown.
        /// </typeparam>
        /// <returns></returns>
        public T[] GetValueArray <T>()
        {
            int myArraySize = this.ArraySize;

            if (myArraySize < 0)
            {
                return(null);
            }

            var values = new T[myArraySize];

            if (myArraySize > 0)
            {
                var enumerator = new SettingArrayEnumerator(mRawValue);

                while (enumerator.Next())
                {
                    values[enumerator.Index] = (T)CreateObjectFromString(enumerator.Current, typeof(T));
                }
            }

            return(values);
        }