/// <summary>
        /// Get double value parameter in ProjectUnits
        /// </summary>
        public static double AsProjectUnitTypeDouble(
            this Parameter param)
        {
            if (param.StorageType != StorageType.Double)
            throw new NotSupportedException(
              "Parameter does not have double value");

              double imperialValue = param.AsDouble();

              Document document = param.Element.Document;

              UnitType ut = ConvertParameterTypeToUnitType(
            param.Definition.ParameterType);

              //FormatOptions fo = document.ProjectUnit // 2013
              //  .get_FormatOptions(ut);

              //DisplayUnitType dut = fo.Units; // 2014

              FormatOptions fo = document.GetUnits() // 2014
            .GetFormatOptions(ut);

              DisplayUnitType dut = fo.DisplayUnits; // 2014

              // Unit Converter
              // http://www.asknumbers.com

              switch (dut)
              {
            #region Length

            case DisplayUnitType.DUT_METERS:
              return imperialValue * METERS_IN_FEET; //feet
            case DisplayUnitType.DUT_CENTIMETERS:
              return imperialValue * METERS_IN_FEET * 100;
            case DisplayUnitType.DUT_DECIMAL_FEET:
              return imperialValue;
            case DisplayUnitType.DUT_DECIMAL_INCHES:
              return imperialValue * 12;
            case DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES:
              NotSupported(dut);
              break;
            case DisplayUnitType.DUT_FRACTIONAL_INCHES:
              NotSupported(dut);
              break;
            case DisplayUnitType.DUT_METERS_CENTIMETERS:
              return imperialValue * METERS_IN_FEET; //feet
            case DisplayUnitType.DUT_MILLIMETERS:
              return imperialValue * METERS_IN_FEET * 1000;

            #endregion // Length

            #region Area

            case DisplayUnitType.DUT_SQUARE_FEET:
              return imperialValue;
            case DisplayUnitType.DUT_ACRES:
              return imperialValue * 1 / 43560.039;
            case DisplayUnitType.DUT_HECTARES:
              return imperialValue * 1 / 107639.104;
            case DisplayUnitType.DUT_SQUARE_CENTIMETERS:
              return imperialValue * Math.Pow(METERS_IN_FEET * 100, 2);
            case DisplayUnitType.DUT_SQUARE_INCHES:
              return imperialValue * Math.Pow(12, 2);
            case DisplayUnitType.DUT_SQUARE_METERS:
              return imperialValue * Math.Pow(METERS_IN_FEET, 2);
            case DisplayUnitType.DUT_SQUARE_MILLIMETERS:
              return imperialValue * Math.Pow(METERS_IN_FEET * 1000, 2);

            #endregion // Area

            #region Volume
            case DisplayUnitType.DUT_CUBIC_FEET:
              return imperialValue;
            case DisplayUnitType.DUT_CUBIC_CENTIMETERS:
              return imperialValue * Math.Pow(METERS_IN_FEET * 100, 3);
            case DisplayUnitType.DUT_CUBIC_INCHES:
              return imperialValue * Math.Pow(12, 3);
            case DisplayUnitType.DUT_CUBIC_METERS:
              return imperialValue * Math.Pow(METERS_IN_FEET, 3);
            case DisplayUnitType.DUT_CUBIC_MILLIMETERS:
              return imperialValue * Math.Pow(METERS_IN_FEET * 1000, 3);
            case DisplayUnitType.DUT_CUBIC_YARDS:
              return imperialValue * 1 / Math.Pow(3, 3);
            case DisplayUnitType.DUT_GALLONS_US:
              return imperialValue * 7.5;
            case DisplayUnitType.DUT_LITERS:
              return imperialValue * 28.31684;

            #endregion // Volume

            default:
              NotSupported(dut);
              break;
              }
              throw new NotSupportedException();
        }
        /// <summary>
        /// Get double value of parameter in meters unit. 
        /// E.g. Length in meters, Area in square meters 
        /// and Volume in Cubic_meters.
        /// Other units not supported yet.
        /// </summary>
        public static double AsMetersValue(
            this Parameter param)
        {
            if (param.StorageType != StorageType.Double)
            throw new NotSupportedException(
              "Parameter does not have double value");

              double imperialValue = param.AsDouble();

              UnitType ut = ConvertParameterTypeToUnitType(
            param.Definition.ParameterType);

              switch (ut)
              {
            case UnitType.UT_Length:
              return imperialValue * METERS_IN_FEET;

            case UnitType.UT_Area:
              return imperialValue * Math.Pow(
            METERS_IN_FEET, 2);

            case UnitType.UT_Volume:
              return imperialValue * Math.Pow(
            METERS_IN_FEET, 3);
              }
              throw new NotSupportedException();
        }
 internal static bool Get(this JsonData data, ref double val)
 {
     bool ret = false;
       if (null != data && (data.IsDouble || data.IsInt || data.IsLong)) {
     ret = true;
     val = data.AsDouble();
       }
       return ret;
 }
 internal static float AsFloat(this JsonData data)
 {
     return (float)data.AsDouble();
 }
Ejemplo n.º 5
0
        public static double? AsNullableDouble(this string inputValue)
        {
            if (string.IsNullOrWhiteSpace(inputValue))
            {
                return null;
            }

            return inputValue.AsDouble();
        }