Skip to content

Commit

Permalink
Merge pull request #3177 from PrismLibrary/dev/ds/argument-null
Browse files Browse the repository at this point in the history
Refactor to ArgumentNullException.ThrowIfNull
  • Loading branch information
dansiegel authored Jul 4, 2024
2 parents 08f92da + 43a12ab commit 7be5a56
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Specialized;
using System.Collections.Specialized;
using Prism.Behaviors;
using Prism.Common;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Properties;

Expand Down Expand Up @@ -29,8 +28,8 @@ public CarouselViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, CarouselView regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool itemsSourceIsSet = regionTarget.ItemsSource != null || regionTarget.IsSet(ItemsView.ItemsSourceProperty);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Prism.Ioc;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;
Expand All @@ -25,11 +24,8 @@ public CollectionViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, CollectionView regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool itemsSourceIsSet = regionTarget.ItemsSource != null || regionTarget.IsSet(ItemsView.ItemsSourceProperty);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Specialized;
using Prism.Ioc;
using System.Collections.Specialized;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;
Expand Down Expand Up @@ -27,8 +26,8 @@ public ContentViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, TContentView regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool contentIsSet = regionTarget.Content != null || regionTarget.IsSet(ContentView.ContentProperty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ public LayoutViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, Layout<View> regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Globalization;
using System.Globalization;
using Prism.Extensions;
using Prism.Ioc;
using Prism.Navigation.Regions.Behaviors;
using Prism.Navigation.Xaml;
using Prism.Properties;
Expand Down Expand Up @@ -75,11 +74,8 @@ IRegion IRegionAdapter.Initialize(object regionTarget, string regionName)
/// <param name="regionTarget">The object to adapt.</param>
protected virtual void AttachDefaultBehaviors(IRegion region, T regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

IRegionBehaviorFactory behaviorFactory = RegionBehaviorFactory;
if (behaviorFactory != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Specialized;
using Prism.Ioc;
using System.Collections.Specialized;
using Prism.Properties;

namespace Prism.Navigation.Regions.Adapters;
Expand All @@ -26,8 +25,8 @@ public ScrollViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, ScrollView regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
ArgumentNullException.ThrowIfNull(region);
ArgumentNullException.ThrowIfNull(regionTarget);

// No binding check required as the ContentProperty is not Bindable
bool contentIsSet = regionTarget.Content != null;
Expand Down

0 comments on commit 7be5a56

Please sign in to comment.