コード例 #1
0
 /// <summary>
 /// Attempts to get a boolean value from the token with the specified <paramref name="path"/>.
 /// </summary>
 /// <param name="array">The parent array.</param>
 /// <param name="path">A <see cref="string"/> that contains a JPath expression.</param>
 /// <param name="result">When this method returns, if the conversion succeeded, contains the parsed boolean value. If the conversion failed, contains <c>false</c>.</param>
 /// <returns><c>true</c> if value was converted successfully; otherwise, <c>false</c>.</returns>
 public static bool TryGetBoolean(this JArray array, string path, out bool result)
 {
     return(JsonTokenUtils.TryGetBoolean(array?.SelectToken(path), out result));
 }
コード例 #2
0
 /// <summary>
 /// Gets the <see cref="bool"/> value of the token matching the specified <paramref name="path"/> and parses
 /// it into an instance of <typeparamref name="T"/>, or the default value of <typeparamref name="T"/> if
 /// <paramref name="path"/> doesn't match a token.
 /// </summary>
 /// <param name="obj">The parent object.</param>
 /// <param name="path">A <see cref="string"/> that contains a JPath expression.</param>
 /// <param name="callback">A callback function used for parsing or converting the token value.</param>
 /// <returns>An instance of <see cref="bool"/>, or <c>false</c> if <paramref name="path"/>
 /// doesn't match a token.</returns>
 public static T GetBoolean <T>(this JObject obj, string path, Func <bool, T> callback)
 {
     return(JsonTokenUtils.TryGetBoolean(obj?.SelectToken(path), out bool result) ? callback(result) : default);
コード例 #3
0
 /// <summary>
 /// Attempts to get a boolean value from the token with the specified <paramref name="index"/>.
 /// </summary>
 /// <param name="array">The parent array.</param>
 /// <param name="index">The index of the token.</param>
 /// <param name="result">When this method returns, if the conversion succeeded, contains the parsed boolean value. If the conversion failed, contains <c>false</c>.</param>
 /// <returns><c>true</c> if value was converted successfully; otherwise, <c>false</c>.</returns>
 public static bool TryGetBoolean(this JArray array, int index, out bool result)
 {
     return(JsonTokenUtils.TryGetBoolean(array?[index], out result));
 }