< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.BaseItemExtensions
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/BaseItemExtensions.cs
Line coverage
93%
Covered lines: 27
Uncovered lines: 2
Coverable lines: 29
Total lines: 132
Line coverage: 93.1%
Branch coverage
85%
Covered branches: 12
Total branches: 14
Branch coverage: 85.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 3/26/2026 - 12:14:14 AM Line coverage: 62% (18/29) Branch coverage: 85.7% (12/14) Total lines: 1325/20/2026 - 12:15:44 AM Line coverage: 62% (18/29) Branch coverage: 78.5% (11/14) Total lines: 1326/28/2026 - 12:15:35 AM Line coverage: 93.1% (27/29) Branch coverage: 85.7% (12/14) Total lines: 132 3/26/2026 - 12:14:14 AM Line coverage: 62% (18/29) Branch coverage: 85.7% (12/14) Total lines: 1325/20/2026 - 12:15:44 AM Line coverage: 62% (18/29) Branch coverage: 78.5% (11/14) Total lines: 1326/28/2026 - 12:15:35 AM Line coverage: 93.1% (27/29) Branch coverage: 85.7% (12/14) Total lines: 132

Coverage delta

Coverage delta 32 -32

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetImagePath(...)100%11100%
HasImage(...)100%11100%
SetImagePath(...)100%11100%
SetImagePath(...)50%2280%
DeepCopy(...)91.66%1212100%
DeepCopy(...)100%11100%
HasChanged(...)100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/BaseItemExtensions.cs

#LineLine coverage
 1#pragma warning disable CS1591
 2
 3using System;
 4using System.Linq;
 5using MediaBrowser.Model.Entities;
 6using MediaBrowser.Model.IO;
 7
 8namespace MediaBrowser.Controller.Entities
 9{
 10    public static class BaseItemExtensions
 11    {
 12        /// <summary>
 13        /// Gets the image path.
 14        /// </summary>
 15        /// <param name="item">The item.</param>
 16        /// <param name="imageType">Type of the image.</param>
 17        /// <returns>System.String.</returns>
 18        public static string GetImagePath(this BaseItem item, ImageType imageType)
 19        {
 220            return item.GetImagePath(imageType, 0);
 21        }
 22
 23        public static bool HasImage(this BaseItem item, ImageType imageType)
 24        {
 14525            return item.HasImage(imageType, 0);
 26        }
 27
 28        /// <summary>
 29        /// Sets the image path.
 30        /// </summary>
 31        /// <param name="item">The item.</param>
 32        /// <param name="imageType">Type of the image.</param>
 33        /// <param name="file">The file.</param>
 34        public static void SetImagePath(this BaseItem item, ImageType imageType, FileSystemMetadata file)
 35        {
 236            item.SetImagePath(imageType, 0, file);
 237        }
 38
 39        /// <summary>
 40        /// Sets the image path.
 41        /// </summary>
 42        /// <param name="item">The item.</param>
 43        /// <param name="imageType">Type of the image.</param>
 44        /// <param name="file">The file.</param>
 45        public static void SetImagePath(this BaseItem item, ImageType imageType, string file)
 46        {
 347            if (file.StartsWith("http", StringComparison.OrdinalIgnoreCase))
 48            {
 349                item.SetImage(
 350                    new ItemImageInfo
 351                    {
 352                        Path = file,
 353                        Type = imageType
 354                    },
 355                    0);
 56            }
 57            else
 58            {
 059                item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
 60            }
 061        }
 62
 63        /// <summary>
 64        /// Copies all properties on object. Skips properties that do not exist.
 65        /// </summary>
 66        /// <param name="source">The source object.</param>
 67        /// <param name="dest">The destination object.</param>
 68        /// <typeparam name="T">Source type.</typeparam>
 69        /// <typeparam name="TU">Destination type.</typeparam>
 70        public static void DeepCopy<T, TU>(this T source, TU dest)
 71            where T : BaseItem
 72            where TU : BaseItem
 73        {
 4474            ArgumentNullException.ThrowIfNull(source);
 75
 4476            ArgumentNullException.ThrowIfNull(dest);
 77
 4478            var destProps = typeof(TU).GetProperties().Where(x => x.CanWrite).ToList();
 79
 968080            foreach (var sourceProp in typeof(T).GetProperties())
 81            {
 82                // We should be able to write to the property
 83                // for both the source and destination type
 84                // This is only false when the derived type hides the base member
 85                // (which we shouldn't copy anyway)
 479686                if (!sourceProp.CanRead || !sourceProp.CanWrite)
 87                {
 88                    continue;
 89                }
 90
 290491                var v = sourceProp.GetValue(source);
 290492                if (v is null)
 93                {
 94                    continue;
 95                }
 96
 140897                var p = destProps.Find(x => x.Name == sourceProp.Name);
 140898                p?.SetValue(dest, v);
 99            }
 44100        }
 101
 102        /// <summary>
 103        /// Copies all properties on newly created object. Skips properties that do not exist.
 104        /// </summary>
 105        /// <param name="source">The source object.</param>
 106        /// <typeparam name="T">Source type.</typeparam>
 107        /// <typeparam name="TU">Destination type.</typeparam>
 108        /// <returns>Destination object.</returns>
 109        public static TU DeepCopy<T, TU>(this T source)
 110            where T : BaseItem
 111            where TU : BaseItem, new()
 112        {
 44113            var dest = new TU();
 44114            source.DeepCopy(dest);
 44115            return dest;
 116        }
 117
 118        /// <summary>
 119        /// Determines if the item has changed.
 120        /// </summary>
 121        /// <param name="source">The source object.</param>
 122        /// <param name="asOf">The timestamp to detect changes as of.</param>
 123        /// <typeparam name="T">Source type.</typeparam>
 124        /// <returns>Whether the item has changed.</returns>
 125        public static bool HasChanged<T>(this T source, DateTime asOf)
 126            where T : BaseItem
 127        {
 59128            ArgumentNullException.ThrowIfNull(source);
 59129            return source.DateModified.Subtract(asOf).Duration().TotalSeconds > 1;
 130        }
 131    }
 132}