/// <summary>Gets the value of a specific pool with respect to a specific position of a <see cref="IExcelDataQuery"/> object. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param> /// <param name="tryGetPoolElement">A method to pick a specific object.</param> /// <param name="rowIndex">The null-based index of the row.</param> /// <param name="columnIndex">The null-based index of the column.</param> /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param> /// <returns>The value.</returns> /// <exception cref="ArgumentException">Thrown, if the user input is invalid.</exception> /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception> public static T GetRequiredPoolValue <T>(this IExcelDataQuery dataQuery, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, int rowIndex = 0, int columnIndex = 0, IExcelDataAdvice dataAdvice = null) { if (dataQuery == null) { throw new ArgumentNullException("dataQuery"); } string objectName; ExcelCellValueState state = dataQuery.TryGetValue <String>(out objectName, rowIndex, columnIndex, dataAdvice); T value; if (state == ExcelCellValueState.ProperValue) { if (tryGetPoolElement(objectName, out value) == true) { return(value); } else { throw new ArgumentException(dataQuery.ToString(rowIndex, columnIndex) + " is no valid name" + GetFormatedDataQueryName(dataQuery) + "."); } } else if (state == ExcelCellValueState.EmptyOrMissingExcelCell) { throw new ArgumentException("Valid pool element name required" + GetFormatedDataQueryName(dataQuery) + "."); } throw new ArgumentException(dataQuery.ToString(rowIndex, columnIndex) + " is no valid input" + GetFormatedDataQueryName(dataQuery) + "."); }
/// <summary>Gets the value of a specific pool with respect to a specific position of a <see cref="IExcelDataQuery"/> object. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param> /// <param name="tryGetPoolElement">A method to pick a specific object.</param> /// <param name="value">The value (output).</param> /// <param name="rowIndex">The null-based index of the row.</param> /// <param name="columnIndex">The null-based index of the column.</param> /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param> /// <returns>A value indicating whether <paramref name="value"/> contains valid data; or the Excel cell is empty.</returns> /// <exception cref="ArgumentException">Thrown, if the user input is invalid, i.e. the name of the pool item is not given its <see cref="System.String"/> representation.</exception> /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception> public static bool TryGetPoolValue <T>(this IExcelDataQuery dataQuery, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, out T value, int rowIndex = 0, int columnIndex = 0, IExcelDataAdvice dataAdvice = null) { if (dataQuery == null) { throw new ArgumentNullException("dataQuery"); } string objectName; ExcelCellValueState state = dataQuery.TryGetValue <String>(out objectName, rowIndex, columnIndex, dataAdvice); if (state == ExcelCellValueState.ProperValue) { return(tryGetPoolElement(objectName, out value)); } else if (state == ExcelCellValueState.EmptyOrMissingExcelCell) { value = default(T); return(false); } throw new ArgumentException(dataQuery.ToString(rowIndex, columnIndex) + " is no valid input" + GetFormatedDataQueryName(dataQuery) + "."); }
/// <summary>Gets the value of a specific pool with respect to a specific property name. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param> /// <param name="propertyName">The name of the property to search.</param> /// <param name="tryGetPoolElement">A method to pick a specific object.</param> /// <param name="value">The value of the property (output).</param> /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param> /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns> /// <exception cref="ArgumentException">Thrown, if the user input is invalid, i.e. the name of the pool item is not given in its <see cref="System.String"/> representation.</exception> /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception> public static bool TryGetPropertyPoolValue <T>(this IExcelDataQuery dataQuery, string propertyName, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, out T value, IExcelDataAdvice dataAdvice = null) { if (dataQuery == null) { throw new ArgumentNullException("dataQuery"); } string objectName; ExcelPropertyValueState state = dataQuery.TryGetPropertyValue <String>(propertyName, out objectName, dataAdvice); if (state == ExcelPropertyValueState.ProperProperty) { return(tryGetPoolElement(objectName, out value)); } else if ((state == ExcelPropertyValueState.NoPropertyFound) || (state == ExcelPropertyValueState.ValueIsEmptyExcelCell)) { value = default(T); return(false); } throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + "."); }
/// <summary>Gets the value of a specific required property. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param> /// <param name="propertyName">The name of the property to search.</param> /// <param name="tryGetPoolElement">A method to pick a specific object.</param> /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param> /// <returns>The value of the property.</returns> /// <exception cref="ArgumentException">Thrown, if no property or valid value is given by the user.</exception> /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception> public static T GetRequiredPropertyPoolValue <T>(this IExcelDataQuery dataQuery, string propertyName, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, IExcelDataAdvice dataAdvice = null) { if (dataQuery == null) { throw new ArgumentNullException("dataQuery"); } string objectName; ExcelPropertyValueState state = dataQuery.TryGetPropertyValue <String>(propertyName, out objectName, dataAdvice); if (state == ExcelPropertyValueState.NoPropertyFound) { throw new ArgumentException("No property with name '" + propertyName + " ' found" + GetFormatedDataQueryName(dataQuery) + "."); } else if (state == ExcelPropertyValueState.NoValidValue) { throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + "."); } else if (state == ExcelPropertyValueState.ValueIsEmptyExcelCell) { throw new ArgumentException("Input required for property '" + propertyName + "'" + GetFormatedDataQueryName(dataQuery) + "."); } T value; if (tryGetPoolElement(objectName, out value) == true) { return(value); } throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + "."); }