/// <summary> /// Retrieves a double value from the specified path in the configuration. /// </summary> /// <param name="path">The path that contains the value to retrieve.</param> /// <param name="default">The default value to return if the value doesn't exist.</param> /// <exception cref="InvalidOperationException">This exception is thrown if the current node is undefined.</exception> /// <returns>The double value defined in the specified path.</returns> public virtual double GetDouble(string path, double @default = 0) { HoconValue value = GetNode(path); if (value == null) { return(@default); } return(value.GetDouble()); }
public static JValue ToJValue(this HoconLiteral hoconLiteral, Func <JValue, JValue>?jValueHandler = null) { if (hoconLiteral == null) { throw new ArgumentNullException(nameof(hoconLiteral)); } var hoconValue = new HoconValue(null) { hoconLiteral, }; JValue jValue; switch (hoconLiteral.LiteralType) { case HoconLiteralType.Null: jValue = JValue.CreateNull(); break; case HoconLiteralType.Whitespace: case HoconLiteralType.UnquotedString: case HoconLiteralType.QuotedString: case HoconLiteralType.TripleQuotedString: jValue = JValue.CreateString(hoconValue.GetString()); break; case HoconLiteralType.Bool: jValue = new JValue(hoconValue.GetBoolean()); break; case HoconLiteralType.Long: case HoconLiteralType.Hex: case HoconLiteralType.Octal: jValue = new JValue(hoconValue.GetLong()); break; case HoconLiteralType.Double: jValue = new JValue(hoconValue.GetDouble()); break; default: throw new InvalidOperationException($"Unknown LiteralType: {hoconLiteral.LiteralType}"); } if (jValueHandler != null) { return(jValueHandler(jValue)); } else { return(jValue); } }
public static object ParseDouble(HoconValue e) { return(e.GetDouble()); }