< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Plugins.Omdb.JsonOmdbNotAvailableInt32Converter
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Plugins/Omdb/JsonOmdbNotAvailableInt32Converter.cs
Line coverage
63%
Covered lines: 7
Uncovered lines: 4
Coverable lines: 11
Total lines: 44
Line coverage: 63.6%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)100%66100%
Write(...)0%620%

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Plugins/Omdb/JsonOmdbNotAvailableInt32Converter.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel;
 3using System.Text.Json;
 4using System.Text.Json.Serialization;
 5
 6namespace MediaBrowser.Providers.Plugins.Omdb
 7{
 8    /// <summary>
 9    /// Converts a string <c>N/A</c> to <c>string.Empty</c>.
 10    /// </summary>
 11    public class JsonOmdbNotAvailableInt32Converter : JsonConverter<int?>
 12    {
 13        /// <inheritdoc />
 14        public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 15        {
 516            if (reader.TokenType == JsonTokenType.String)
 17            {
 418                var str = reader.GetString();
 419                if (str is null || str.Equals("N/A", StringComparison.OrdinalIgnoreCase))
 20                {
 321                    return null;
 22                }
 23
 124                var converter = TypeDescriptor.GetConverter(typeToConvert);
 125                return (int?)converter.ConvertFromString(str);
 26            }
 27
 128            return JsonSerializer.Deserialize<int>(ref reader, options);
 29        }
 30
 31        /// <inheritdoc />
 32        public override void Write(Utf8JsonWriter writer, int? value, JsonSerializerOptions options)
 33        {
 034            if (value.HasValue)
 35            {
 036                writer.WriteNumberValue(value.Value);
 37            }
 38            else
 39            {
 040                writer.WriteNullValue();
 41            }
 042        }
 43    }
 44}