Пример #1
0
        /// <summary>Gets the value of a specific property.
        /// </summary>
        /// <typeparam name="TEnum">The type of the value which is assumed to be a enumeration.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="value">The value of the property (output).</param>
        /// <param name="enumStringRepresentationUsage">The method how to compute the <see cref="System.String"/> representation of the enumeration <typeparamref name="TEnum"/>.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value, the second column is standard.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="TEnum"/> does not represents a specific enumeration.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static ExcelPropertyValueState TryGetPropertyValue <TEnum>(this IExcelDataQuery dataQuery, string propertyName, out TEnum value, EnumStringRepresentationUsage enumStringRepresentationUsage, int propertyValueColumnIndex = 1)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            int rowIndex;

            if (dataQuery.TryGetRowIndexOfPropertyName(propertyName, out rowIndex) == false)
            {
                value = default(TEnum);
                return(ExcelPropertyValueState.NoPropertyFound);
            }
            ExcelCellValueState state = dataQuery.TryGetValue <TEnum>(enumStringRepresentationUsage, out value, rowIndex, propertyValueColumnIndex);

            if (state == ExcelCellValueState.ProperValue)
            {
                return(ExcelPropertyValueState.ProperProperty);
            }
            else if (state == ExcelCellValueState.EmptyOrMissingExcelCell)
            {
                return(ExcelPropertyValueState.ValueIsEmptyExcelCell);
            }
            else
            {
                return(ExcelPropertyValueState.NoValidValue);
            }
        }
Пример #2
0
        /// <summary>Gets the value of a specific property.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="value">The value of the property (output).</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents the type of a specific enumeration.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static ExcelPropertyValueState TryGetPropertyValue <T>(this IExcelDataQuery dataQuery, string propertyName, out T value, IExcelDataAdvice dataAdvice = null, int propertyValueColumnIndex = 1)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            int rowIndex;

            if (dataQuery.TryGetRowIndexOfPropertyName(propertyName, out rowIndex) == false)
            {
                value = default(T);
                return(ExcelPropertyValueState.NoPropertyFound);
            }
            ExcelCellValueState state = dataQuery.TryGetValue <T>(out value, rowIndex, propertyValueColumnIndex, dataAdvice);

            if (state == ExcelCellValueState.ProperValue)
            {
                return(ExcelPropertyValueState.ProperProperty);
            }
            else if (state == ExcelCellValueState.EmptyOrMissingExcelCell)
            {
                return(ExcelPropertyValueState.ValueIsEmptyExcelCell);
            }
            else
            {
                return(ExcelPropertyValueState.NoValidValue);
            }
        }
Пример #3
0
        /// <summary>Gets the value of a specific required property.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value.</param>
        /// <returns>The value of the property.</returns>
        /// <exception cref="ArgumentException">Thrown, if no property or valid value is given by the user or if
        /// <typeparamref name="T"/> represents the type of a specific enumeration.</exception>
        public static T GetRequiredPropertyValue <T>(this IExcelDataQuery dataQuery, string propertyName, IExcelDataAdvice dataAdvice = null, int propertyValueColumnIndex = 1)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            T   value;
            int rowIndex;

            if (dataQuery.TryGetRowIndexOfPropertyName(propertyName, out rowIndex) == false)
            {
                throw new ArgumentException("No property with name '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            if (dataQuery.TryGetValue <T>(out value, rowIndex, propertyValueColumnIndex, dataAdvice) == ExcelCellValueState.ProperValue)
            {
                return(value);
            }
            throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
        }
Пример #4
0
        /// <summary>Gets the value of a specific required property.
        /// </summary>
        /// <typeparam name="TEnum">The type of the value which is assumed to be a enumeration.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="enumStringRepresentationUsage">The method how to compute the <see cref="System.String"/> representation of the enumeration <typeparamref name="TEnum"/>.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value, the second column is standard.</param>
        /// <returns>The value of the property.</returns>
        /// <exception cref="ArgumentException">Thrown, if no property or valid value is given by the user or if
        /// <typeparamref name="TEnum"/> does not represents a specific enumeration.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static TEnum GetRequiredPropertyValue <TEnum>(this IExcelDataQuery dataQuery, string propertyName, EnumStringRepresentationUsage enumStringRepresentationUsage, int propertyValueColumnIndex = 1)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            TEnum value;
            int   rowIndex;

            if (dataQuery.TryGetRowIndexOfPropertyName(propertyName, out rowIndex) == false)
            {
                throw new ArgumentException("No property with name '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            if (dataQuery.TryGetValue <TEnum>(enumStringRepresentationUsage, out value, rowIndex, propertyValueColumnIndex) == ExcelCellValueState.ProperValue)
            {
                return(value);
            }
            throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
        }