Example #1
0
    /// <summary>
    /// Helper method to go find the value(s) of a property and put into a List<double>
    /// </summary>
    private double[] AddValuesToList(string SubPropertyName)
    {
        if (ArraySizeNumber == -1)
        {
            ArraySizeNumber = Convert.ToInt32(ExpressionFunction.Evaluate(ArraySize, My));
        }

        double[] Values = new double[ArraySizeNumber];
        int      i      = 0;

        foreach (string PropertyName in Propertys)
        {
            object Obj = Util.GetVariable(PropertyName + SubPropertyName, My);
            if (Obj == null)
            {
                throw new Exception("Cannot find: " + PropertyName + " in ArrayBiomass: " + My.Name);
            }

            if (Obj is IEnumerable)
            {
                foreach (object Value in Obj as IEnumerable)
                {
                    Values[i] = Convert.ToDouble(Value);
                    i++;
                }
            }
            else
            {
                Values[i] = Convert.ToDouble(Obj);
                i++;
            }
        }
        return(Values);
    }
Example #2
0
        /// <summary>Adds the values to list.</summary>
        /// <param name="SubPropertyName">Name of the sub property.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Cannot find:  + PropertyName +  in ArrayBiomass:  + this.Name</exception>
        private double[] AddValuesToList(string SubPropertyName)
        {
            if (ArraySizeNumber == -1)
            {
                ArraySizeNumber = Convert.ToInt32(ExpressionFunction.Evaluate(ArraySize, this), CultureInfo.InvariantCulture);
            }

            double[] Values = new double[ArraySizeNumber];
            int      i      = 0;

            foreach (string PropertyName in Propertys)
            {
                object Obj = this.FindByPath(PropertyName + SubPropertyName)?.Value;
                if (Obj == null)
                {
                    throw new Exception("Cannot find: " + PropertyName + " in ArrayBiomass: " + this.Name);
                }

                if (Obj is IEnumerable)
                {
                    foreach (object Value in Obj as IEnumerable)
                    {
                        Values[i] = Convert.ToDouble(Value,
                                                     System.Globalization.CultureInfo.InvariantCulture);
                        i++;
                    }
                }
                else
                {
                    Values[i] = Convert.ToDouble(Obj,
                                                 System.Globalization.CultureInfo.InvariantCulture);
                    i++;
                }
            }
            return(Values);
        }