コード例 #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, true);
                int iElem      = 0;
                while (enumerator.Next())
                {
                    values[iElem] = (T)CreateObjectFromString(enumerator.Current, type);
                    ++iElem;
                }
            }

            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, true);
                int iElem      = 0;
                while (enumerator.Next())
                {
                    values[iElem] = CreateObjectFromString(enumerator.Current, elementType);
                    ++iElem;
                }
            }

            return(values);
        }
コード例 #3
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 new ArgumentException("Jagged arrays are not supported.");
            }

            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);
        }
コード例 #4
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>()
        {
            if (typeof(T).IsArray)
            {
                throw new ArgumentException("Jagged arrays are not supported.");
            }

            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);
        }
コード例 #5
0
        private int CalculateArraySize()
        {
            int size       = 0;
            var enumerator = new SettingArrayEnumerator(mRawValue, false);

            while (enumerator.Next())
            {
                ++size;
            }

            return(enumerator.IsValid ? size : -1);
        }
コード例 #6
0
ファイル: Setting.cs プロジェクト: ettele/SharpConfig
        /// <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);
        }
コード例 #7
0
ファイル: Setting.cs プロジェクト: ettele/SharpConfig
        /// <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);
        }