Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ArgumentNullException.ThrowIfNull helper method #8503

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Emby.Dlna/ContentDirectory/ContentDirectoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public string GetServiceXml()
/// <inheritdoc />
public Task<ControlResponse> ProcessControlRequestAsync(ControlRequest request)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);

var profile = _dlna.GetProfile(request.Headers) ?? _dlna.GetDefaultProfile();

Expand Down
10 changes: 2 additions & 8 deletions Emby.Dlna/ContentDirectory/ControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,9 @@ public class ControlHandler : BaseControlHandler
/// <inheritdoc />
protected override void WriteResult(string methodName, IReadOnlyDictionary<string, string> methodParams, XmlWriter xmlWriter)
{
if (xmlWriter == null)
{
throw new ArgumentNullException(nameof(xmlWriter));
}
ArgumentNullException.ThrowIfNull(xmlWriter);

if (methodParams == null)
{
throw new ArgumentNullException(nameof(methodParams));
}
ArgumentNullException.ThrowIfNull(methodParams);

const string DeviceId = "test";

Expand Down
10 changes: 2 additions & 8 deletions Emby.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public DeviceProfile GetDefaultProfile()
/// <inheritdoc />
public DeviceProfile? GetProfile(DeviceIdentification deviceInfo)
{
if (deviceInfo == null)
{
throw new ArgumentNullException(nameof(deviceInfo));
}
ArgumentNullException.ThrowIfNull(deviceInfo);

var profile = GetProfiles()
.FirstOrDefault(i => i.Identification != null && IsMatch(deviceInfo, i.Identification));
Expand Down Expand Up @@ -170,10 +167,7 @@ private bool IsRegexOrSubstringMatch(string input, string pattern)
/// <inheritdoc />
public DeviceProfile? GetProfile(IHeaderDictionary headers)
{
if (headers == null)
{
throw new ArgumentNullException(nameof(headers));
}
ArgumentNullException.ThrowIfNull(headers);

var profile = GetProfiles().FirstOrDefault(i => i.Identification != null && IsMatch(headers, i.Identification));
if (profile == null)
Expand Down
15 changes: 3 additions & 12 deletions Emby.Dlna/PlayTo/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,7 @@ private XElement ParseResponse(string xml)

private static UBaseObject CreateUBaseObject(XElement container, string trackUri)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
ArgumentNullException.ThrowIfNull(container);

var url = container.GetValue(UPnpNamespaces.Res);

Expand All @@ -958,10 +955,7 @@ private static UBaseObject CreateUBaseObject(XElement container, string trackUri

private static string[] GetProtocolInfo(XElement container)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
ArgumentNullException.ThrowIfNull(container);

var resElement = container.Element(UPnpNamespaces.Res);

Expand Down Expand Up @@ -1183,10 +1177,7 @@ public static async Task<Device> CreateuPnpDeviceAsync(Uri url, IHttpClientFacto
#nullable enable
private static DeviceIcon CreateIcon(XElement element)
{
if (element == null)
{
throw new ArgumentNullException(nameof(element));
}
ArgumentNullException.ThrowIfNull(element);

var width = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("width"));
var height = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("height"));
Expand Down
5 changes: 1 addition & 4 deletions Emby.Dlna/PlayTo/TransportCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ private static ServiceAction ServiceActionFromXml(XElement container)

private static Argument ArgumentFromXml(XElement container)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
ArgumentNullException.ThrowIfNull(container);

return new Argument
{
Expand Down
5 changes: 1 addition & 4 deletions Emby.Dlna/PlayTo/UpnpContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public class UpnpContainer : UBaseObject
{
public static UBaseObject Create(XElement container)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
ArgumentNullException.ThrowIfNull(container);

return new UBaseObject
{
Expand Down
5 changes: 1 addition & 4 deletions Emby.Dlna/PlayTo/uBaseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public string MediaType

public bool Equals(UBaseObject obj)
{
if (obj == null)
{
throw new ArgumentNullException(nameof(obj));
}
ArgumentNullException.ThrowIfNull(obj);

return string.Equals(Id, obj.Id, StringComparison.Ordinal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ protected virtual void OnConfigurationUpdated()
/// <exception cref="ArgumentNullException"><c>newConfiguration</c> is <c>null</c>.</exception>
public virtual void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration)
{
if (newConfiguration == null)
{
throw new ArgumentNullException(nameof(newConfiguration));
}
ArgumentNullException.ThrowIfNull(newConfiguration);

ValidateCachePath(newConfiguration);

Expand Down
5 changes: 1 addition & 4 deletions Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,10 +1188,7 @@ private async Task<BaseItem> GetChannelItemEntityAsync(ChannelItemInfo info, ICh

internal IChannel GetChannelProvider(Channel channel)
{
if (channel == null)
{
throw new ArgumentNullException(nameof(channel));
}
ArgumentNullException.ThrowIfNull(channel);

var result = GetAllChannels()
.FirstOrDefault(i => GetInternalChannelId(i.Name).Equals(channel.ChannelId) || string.Equals(i.Name, channel.Name, StringComparison.OrdinalIgnoreCase));
Expand Down
5 changes: 1 addition & 4 deletions Emby.Server.Implementations/Data/SqliteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public static class SqliteExtensions

public static void RunQueries(this SQLiteDatabaseConnection connection, string[] queries)
{
if (queries == null)
{
throw new ArgumentNullException(nameof(queries));
}
ArgumentNullException.ThrowIfNull(queries);

connection.RunInTransaction(conn =>
{
Expand Down
85 changes: 17 additions & 68 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,7 @@ public void Initialize(SqliteUserDataRepository userDataRepo, IUserManager userM

public void SaveImages(BaseItem item)
{
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
ArgumentNullException.ThrowIfNull(item);

CheckDisposed();

Expand Down Expand Up @@ -617,10 +614,7 @@ public void SaveImages(BaseItem item)
/// </exception>
public void SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
ArgumentNullException.ThrowIfNull(items);

cancellationToken.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -2085,10 +2079,7 @@ public void SaveChapters(Guid id, IReadOnlyList<ChapterInfo> chapters)
throw new ArgumentNullException(nameof(id));
}

if (chapters == null)
{
throw new ArgumentNullException(nameof(chapters));
}
ArgumentNullException.ThrowIfNull(chapters);

var idBlob = id.ToByteArray();

Expand Down Expand Up @@ -2557,10 +2548,7 @@ private string GetGroupBy(InternalItemsQuery query)

public int GetCount(InternalItemsQuery query)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

CheckDisposed();

Expand Down Expand Up @@ -2613,10 +2601,7 @@ public int GetCount(InternalItemsQuery query)

public List<BaseItem> GetItemList(InternalItemsQuery query)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

CheckDisposed();

Expand Down Expand Up @@ -2794,10 +2779,7 @@ private void LogQueryTime(string methodName, string commandText, DateTime startD

public QueryResult<BaseItem> GetItems(InternalItemsQuery query)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

CheckDisposed();

Expand Down Expand Up @@ -3174,10 +3156,7 @@ private string MapOrderByField(string name, InternalItemsQuery query)

public List<Guid> GetItemIdsList(InternalItemsQuery query)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

CheckDisposed();

Expand Down Expand Up @@ -4837,10 +4816,7 @@ private void ExecuteWithSingleParam(IDatabaseConnection db, string query, ReadOn

public List<string> GetPeopleNames(InternalPeopleQuery query)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

CheckDisposed();

Expand Down Expand Up @@ -4880,10 +4856,7 @@ public List<string> GetPeopleNames(InternalPeopleQuery query)

public List<PersonInfo> GetPeople(InternalPeopleQuery query)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

CheckDisposed();

Expand Down Expand Up @@ -4999,10 +4972,7 @@ private void UpdateAncestors(Guid itemId, List<Guid> ancestorIds, IDatabaseConne
throw new ArgumentNullException(nameof(itemId));
}

if (ancestorIds == null)
{
throw new ArgumentNullException(nameof(ancestorIds));
}
ArgumentNullException.ThrowIfNull(ancestorIds);

CheckDisposed();

Expand Down Expand Up @@ -5175,10 +5145,7 @@ private List<string> GetItemValueNames(int[] itemValueTypes, IReadOnlyList<strin

private QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetItemValues(InternalItemsQuery query, int[] itemValueTypes, string returnType)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

if (!query.Limit.HasValue)
{
Expand Down Expand Up @@ -5531,10 +5498,7 @@ private void UpdateItemValues(Guid itemId, List<(int MagicNumber, string Value)>
throw new ArgumentNullException(nameof(itemId));
}

if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
ArgumentNullException.ThrowIfNull(values);

CheckDisposed();

Expand Down Expand Up @@ -5607,10 +5571,7 @@ public void UpdatePeople(Guid itemId, List<PersonInfo> people)
throw new ArgumentNullException(nameof(itemId));
}

if (people == null)
{
throw new ArgumentNullException(nameof(people));
}
ArgumentNullException.ThrowIfNull(people);

CheckDisposed();

Expand Down Expand Up @@ -5710,10 +5671,7 @@ public List<MediaStream> GetMediaStreams(MediaStreamQuery query)
{
CheckDisposed();

if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

var cmdText = _mediaStreamSaveColumnsSelectQuery;

Expand Down Expand Up @@ -5766,10 +5724,7 @@ public void SaveMediaStreams(Guid id, IReadOnlyList<MediaStream> streams, Cancel
throw new ArgumentNullException(nameof(id));
}

if (streams == null)
{
throw new ArgumentNullException(nameof(streams));
}
ArgumentNullException.ThrowIfNull(streams);

cancellationToken.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -6107,10 +6062,7 @@ public List<MediaAttachment> GetMediaAttachments(MediaAttachmentQuery query)
{
CheckDisposed();

if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);

var cmdText = _mediaAttachmentSaveColumnsSelectQuery;

Expand Down Expand Up @@ -6152,10 +6104,7 @@ public List<MediaAttachment> GetMediaAttachments(MediaAttachmentQuery query)
throw new ArgumentException("Guid can't be empty.", nameof(id));
}

if (attachments == null)
{
throw new ArgumentNullException(nameof(attachments));
}
ArgumentNullException.ThrowIfNull(attachments);

cancellationToken.ThrowIfCancellationRequested();

Expand Down
Loading