private static TResult? TryGetPropertyEx()

in JetBrains.Etw.HostService.Updater/src/Util/JsonUtil.cs [30:48]


    private static TResult? TryGetPropertyEx<TResult>(this JsonElement element, [NotNull] string propertyName, [NotNull] Func<JsonElement, TResult> func) where TResult : struct
    {
      if (func == null)
        throw new ArgumentNullException(nameof(func));
      if (!element.TryGetProperty(propertyName, out var childElement))
        return null;
      try
      {
        return func(childElement);
      }
      catch (FormatException e)
      {
        throw new FormatException($"Failed to parse property {propertyName}", e);
      }
      catch (InvalidOperationException e)
      {
        throw new InvalidOperationException($"Failed to get property {propertyName}", e);
      }
    }