示例#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>
        /// <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>The values of this setting as an array.</returns>
        public T[] GetValueArray <T>()
        {
            var type = typeof(T);

            if (type.IsArray)
            {
                throw CreateJaggedArraysNotSupportedEx(type);
            }

            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, type);
                }
            }

            return(values);
        }
示例#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>
        /// <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>The values of this setting as an array.</returns>
        public object[] GetValueArray(Type elementType)
        {
            if (elementType.IsArray)
            {
                throw CreateJaggedArraysNotSupportedEx(elementType);
            }

            int myArraySize = this.ArraySize;

            if (ArraySize < 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);
        }