/// <summary> /// Retrieves a boolean 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 boolean value defined in the specified path.</returns> public virtual bool GetBoolean(string path, bool @default = false) { HoconValue value = GetNode(path); if (value == null) { return(@default); } return(value.GetBoolean()); }
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 ParseBool(HoconValue e) { return(e.GetBoolean()); }