mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #5876 from Bond-009/nullref5
DeepCopy: Throw ArgumentNullException if one of the args is null
This commit is contained in:
commit
24103d0953
@ -1,5 +1,7 @@
|
|||||||
|
#nullable enable
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
@ -64,9 +66,19 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
/// <param name="source">The source object.</param>
|
/// <param name="source">The source object.</param>
|
||||||
/// <param name="dest">The destination object.</param>
|
/// <param name="dest">The destination object.</param>
|
||||||
public static void DeepCopy<T, TU>(this T source, TU dest)
|
public static void DeepCopy<T, TU>(this T source, TU dest)
|
||||||
where T : BaseItem
|
where T : BaseItem
|
||||||
where TU : BaseItem
|
where TU : BaseItem
|
||||||
{
|
{
|
||||||
|
if (source == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(dest));
|
||||||
|
}
|
||||||
|
|
||||||
var destProps = typeof(TU).GetProperties().Where(x => x.CanWrite).ToList();
|
var destProps = typeof(TU).GetProperties().Where(x => x.CanWrite).ToList();
|
||||||
|
|
||||||
foreach (var sourceProp in typeof(T).GetProperties())
|
foreach (var sourceProp in typeof(T).GetProperties())
|
||||||
@ -99,8 +111,8 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source object.</param>
|
/// <param name="source">The source object.</param>
|
||||||
public static TU DeepCopy<T, TU>(this T source)
|
public static TU DeepCopy<T, TU>(this T source)
|
||||||
where T : BaseItem
|
where T : BaseItem
|
||||||
where TU : BaseItem, new()
|
where TU : BaseItem, new()
|
||||||
{
|
{
|
||||||
var dest = new TU();
|
var dest = new TU();
|
||||||
source.DeepCopy(dest);
|
source.DeepCopy(dest);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user