Пример #1
0
        /// <summary>Gets the value of a specific Excel cell.
        /// </summary>
        /// <typeparam name="TEnum">The type of the enumeration.</typeparam>
        /// <param name="excelCell">The Excel cell.</param>
        /// <param name="enumStringRepresentationUsage">The method how to compute the <see cref="System.String"/> representation of the enumeration <typeparamref name="TEnum"/>.</param>
        /// <param name="value">The value of the <paramref name="excelCell"/> (output).</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="TEnum"/> does not represent a enumeration.</exception>
        public static bool TryGetCellValue <TEnum>(object excelCell, EnumStringRepresentationUsage enumStringRepresentationUsage, out TEnum value)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            if (typeof(TEnum).IsEnum)
            {
                string tableValue = ((string)excelCell);

                return(EnumString <TEnum> .TryParse(tableValue, out value, enumStringRepresentationUsage));
            }
            throw new ArgumentException(String.Format(ExceptionMessages.ArgumentIsInvalid, "EnumType: " + typeof(TEnum).ToString()), "TEnum");
        }
Пример #2
0
        /// <summary>Gets the <see cref="LoggingLevel"/> flag with respect to the config file.
        /// </summary>
        /// <returns>The loaded <see cref="ExcelPoolLoggingLevel"/> or a standard value.</returns>
        internal static ExcelPoolLoggingLevel GetLoggingLevelFromConfigFile()
        {
            string loggingLevelAsString;

            if (ExcelAddIn.Configuration.GeneralSettings.TryGetValue(m_LoggingLevelConfigKey, out loggingLevelAsString) == false)
            {
                sm_LoggingLevel = ExcelPoolLoggingLevel.None;
            }
            else
            {
                if (EnumString <ExcelPoolLoggingLevel> .TryParse(loggingLevelAsString, out sm_LoggingLevel, EnumStringRepresentationUsage.StringAttribute) == false)
                {
                    throw new ConfigurationFileErrorException("Configuration file corrupt:" + loggingLevelAsString + " is no valid input for the global logfile logging level.");
                }
            }
            return(sm_LoggingLevel);
        }