Exemplo n.º 1
0
        /// <summary>
        ///  This is used by the Stdev and Var functions to parse the values it receives from a cell range or refreence.
        /// </summary>
        /// <param name="IgnoreHiddenValues">This controls wether you should skip Hidden Values or not.</param>
        /// <param name="valueToParse">This is the value that will be parsed.</param>
        /// <param name="context">Unused, this is information about where the function is being executed.</param>
        /// <param name="includeLogicals">A flag to control wether you should parse logicals or not.</param>
        /// <param name="parsedValue">This out value is the parse value in double form.</param>
        /// <param name="theInputContainedOnlyStrings">This bool flag shows if only string inputs were given.</param>
        /// <returns>Returns true if the parseing succeded and false if it fails.</returns>
        public static bool TryToParseValuesFromInputArgumentByRefrenceOrRange(bool IgnoreHiddenValues, ExcelDataProvider.ICellInfo valueToParse, ParsingContext context, bool includeLogicals, out double parsedValue, out bool theInputContainedOnlyStrings)
        {
            var shouldIgnore = CellStateHelper.ShouldIgnore(IgnoreHiddenValues, valueToParse, context);
            var isNumeric    = ConvertUtil.IsNumeric(valueToParse.Value);
            var isABoolean   = valueToParse.Value is bool;

            if (!shouldIgnore && isNumeric && !isABoolean)
            {
                parsedValue = valueToParse.ValueDouble;
                theInputContainedOnlyStrings = false;
                return(true);
            }
            if (includeLogicals)
            {
                if (isABoolean)
                {
                    if ((bool)valueToParse.Value == true)
                    {
                        parsedValue = 1;
                    }
                    else
                    {
                        parsedValue = 0;
                    }
                    theInputContainedOnlyStrings = false;
                    return(true);
                }
                if (ConvertUtil.TryParseObjectToDecimal(valueToParse.ValueDouble, out double numericValue))
                {
                    parsedValue = numericValue;
                    theInputContainedOnlyStrings = false;
                    return(true);
                }
                parsedValue = 0.0;
                theInputContainedOnlyStrings = false;
                return(false);
            }
            else
            {
                if (isABoolean)
                {
                    parsedValue = valueToParse.ValueDoubleLogical;
                    theInputContainedOnlyStrings = false;
                    return(false);
                }
                if (ConvertUtil.TryParseObjectToDecimal(valueToParse.ValueDouble, out double numericValue))
                {
                    parsedValue = numericValue;
                    theInputContainedOnlyStrings = false;
                    return(false);
                }
                parsedValue = 0.0;
                theInputContainedOnlyStrings = false;
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// This is used by the Stdev and Var functions to parse the values it receives from a direct input.
 /// </summary>
 /// <param name="IgnoreHiddenValues">This controls wether you should skip Hidden Values or not.</param>
 /// <param name="valueToParse">This is the value that will be parsed.</param>
 /// <param name="context">Unused, this is information about where the function is being executed.</param>
 /// <param name="parsedValue">This out value is the parse value in double form.</param>
 /// <param name="theInputContainedOnlyStrings">This bool flag shows if only string inputs were given.</param>
 /// <returns>Returns true if the parseing succeded and false if it fails.</returns>
 public static bool TryToParseValuesFromInputArgument(bool IgnoreHiddenValues, FunctionArgument valueToParse, ParsingContext context, out double parsedValue, out bool theInputContainedOnlyStrings)
 {
     if (ConvertUtil.IsNumeric(valueToParse.Value) && !CellStateHelper.ShouldIgnore(IgnoreHiddenValues, valueToParse, context))
     {
         parsedValue = ConvertUtil.GetValueDouble(valueToParse.Value);
         theInputContainedOnlyStrings = false;
         return(true);
     }
     if (valueToParse.Value is string && ConvertUtil.TryParseObjectToDecimal(valueToParse.Value, out double result))
     {
         parsedValue = result;
         theInputContainedOnlyStrings = false;
         return(true);
     }
     parsedValue = 0.0;
     theInputContainedOnlyStrings = true;
     return(false);
 }