Skip to content

Commit

Permalink
chore: resolving build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Feb 25, 2024
1 parent 637e6a9 commit 2b9b78d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 47 deletions.
20 changes: 12 additions & 8 deletions src/Maui/Prism.Maui/Dialogs/DialogService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Prism.Commands;
using Prism.Common;
using Prism.Ioc;
using Prism.Navigation;
using Prism.Dialogs.Xaml;
using Prism.Mvvm;
using Prism.Navigation;

#nullable enable
namespace Prism.Dialogs;

/// <summary>
Expand All @@ -22,8 +23,10 @@ public sealed class DialogService : IDialogService
/// <exception cref="ArgumentNullException">Throws when any constructor arguments are null.</exception>
public DialogService(IContainerProvider container, IPageAccessor pageAccessor)
{
_container = container ?? throw new ArgumentNullException(nameof(container));
_pageAccessor = pageAccessor ?? throw new ArgumentNullException(nameof(pageAccessor));
ArgumentNullException.ThrowIfNull(container);
ArgumentNullException.ThrowIfNull(pageAccessor);
_container = container;
_pageAccessor = pageAccessor;
}

/// <inheritdoc/>
Expand All @@ -37,7 +40,8 @@ public void ShowDialog(string name, IDialogParameters parameters, DialogCallback
// This needs to be resolved when called as a Module could load any time
// and register new dialogs
var registry = _container.Resolve<IDialogViewRegistry>();
var view = registry.CreateView(_container, UriParsingHelper.GetSegmentName(name)) as View;
var view = registry.CreateView(_container, UriParsingHelper.GetSegmentName(name)) as View
?? throw new ViewCreationException(name, ViewType.Dialog);

var currentPage = _pageAccessor.Page;
dialogModal = _container.Resolve<IDialogContainer>();
Expand Down Expand Up @@ -76,12 +80,12 @@ async Task DialogAware_RequestClose(IDialogResult outResult)

if (dex.Message != DialogException.CanCloseIsFalse)
{
await InvokeError(callback, dex, parameters);
await DialogService.InvokeError(callback, dex, parameters);
}
}
catch (Exception ex)
{
await InvokeError(callback, ex, parameters);
await DialogService.InvokeError(callback, ex, parameters);
}
finally
{
Expand Down Expand Up @@ -120,7 +124,7 @@ async Task DialogAware_RequestClose(IDialogResult outResult)
}
}

private async Task InvokeError(DialogCallback callback, Exception exception, IDialogParameters parameters)
private static async Task InvokeError(DialogCallback callback, Exception exception, IDialogParameters parameters)
{
var result = new DialogResult
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Common;
using Prism.Common;

namespace Prism.Navigation;

Expand All @@ -10,6 +10,7 @@ public static class INavigationServiceExtensions
/// <summary>
/// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack.
/// </summary>
/// <param name="navigationService">Service for handling navigation between views</param>
/// <param name="name">The name of the View to navigate back to</param>
/// <returns><see cref="INavigationResult"/> indicating whether the request was successful or if there was an encountered <see cref="Exception"/>.</returns>
public static Task<INavigationResult> GoBackToAsync(this INavigationService navigationService, string name) =>
Expand Down Expand Up @@ -52,6 +53,7 @@ public static Task<INavigationResult> GoBackToRootAsync(this INavigationService
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="uri"/>.
/// </summary>
/// <param name="navigationService">Service for handling navigation between views</param>
/// <param name="uri">The Uri to navigate to</param>
/// <example>
/// NavigateAsync(new Uri("MainPage?id=3&amp;name=brian", UriKind.RelativeSource));
Expand All @@ -78,13 +80,15 @@ public static Task<INavigationResult> NavigateAsync(this INavigationService navi
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="name"/>.
/// </summary>
/// <param name="navigationService">Service for handling navigation between views</param>
/// <param name="name">The name of the target to navigate to.</param>
public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, string name) =>
navigationService.NavigateAsync(name, default(INavigationParameters));

/// <summary>
/// Initiates navigation to the target specified by the <paramref name="name"/>.
/// </summary>
/// <param name="navigationService">Service for handling navigation between views</param>
/// <param name="name">The name of the target to navigate to.</param>
/// <param name="parameters">The navigation parameters</param>
public static Task<INavigationResult> NavigateAsync(this INavigationService navigationService, string name, INavigationParameters parameters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Specialized;
using System.Collections.Specialized;
using Prism.Common;

namespace Prism.Navigation.Regions.Behaviors;
Expand All @@ -11,7 +11,7 @@ namespace Prism.Navigation.Regions.Behaviors;
/// </summary>
/// <remarks>
/// This class can also sync the active state for any scoped regions directly on the view based on the <see cref="SyncActiveStateAttribute"/>.
/// If you use the <see cref="Regions.Region.Add(VisualElement,string,bool)" /> method with the createRegionManagerScope option, the scoped manager will be attached to the view.
/// If you use the <see cref="Regions.Region.Add(object,string,bool)" /> method with the createRegionManagerScope option, the scoped manager will be attached to the view.
/// </remarks>
public class RegionActiveAwareBehavior : IRegionBehavior
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization;

namespace Prism.Navigation.Regions.Behaviors;

/// <summary>
/// Represents errors that occurred during region creation.
/// </summary>
[Serializable]
public partial class RegionCreationException : Exception
{
/// <summary>
Expand Down Expand Up @@ -35,14 +34,4 @@ public RegionCreationException(string message, Exception inner)
: base(message, inner)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="RegionCreationException"/> class with serialized data.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected RegionCreationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Globalization;
using System.Globalization;
using Prism.Common;
using Prism.Ioc;
using Prism.Mvvm;
Expand Down Expand Up @@ -27,11 +27,8 @@ public class RegionNavigationContentLoader : IRegionNavigationContentLoader
/// <exception cref="ArgumentException">when a new view cannot be created for the navigation request.</exception>
public object LoadContent(IRegion region, NavigationContext navigationContext)
{
if (region == null)
throw new ArgumentNullException(nameof(region));

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

string candidateTargetContract = GetContractFromNavigationContext(navigationContext);

Expand All @@ -58,6 +55,7 @@ public object LoadContent(IRegion region, NavigationContext navigationContext)
/// Provides a new item for the region based on the supplied candidate target contract name.
/// </summary>
/// <param name="candidateTargetContract">The target contract to build.</param>
/// <param name="region">The <see cref="IRegion"/> to create the new Region Item in.</param>
/// <returns>An instance of an item to put into the <see cref="IRegion"/>.</returns>
protected virtual object CreateNewRegionItem(string candidateTargetContract, IRegion region)
{
Expand Down Expand Up @@ -89,7 +87,7 @@ protected virtual object CreateNewRegionItem(string candidateTargetContract, IRe
/// <returns>The candidate contract to seek within the <see cref="IRegion"/> and to use, if not found, when resolving from the container.</returns>
protected virtual string GetContractFromNavigationContext(NavigationContext navigationContext)
{
if (navigationContext == null) throw new ArgumentNullException(nameof(navigationContext));
ArgumentNullException.ThrowIfNull(navigationContext);

var candidateTargetContract = UriParsingHelper.EnsureAbsolute(navigationContext.Uri).AbsolutePath;
candidateTargetContract = candidateTargetContract.TrimStart('/');
Expand All @@ -104,34 +102,31 @@ protected virtual string GetContractFromNavigationContext(NavigationContext navi
/// <returns>An enumerable of candidate objects from the <see cref="IRegion"/></returns>
protected virtual IEnumerable<VisualElement> GetCandidatesFromRegion(IRegion region, string candidateNavigationContract)
{
if (region is null)
{
throw new ArgumentNullException(nameof(region));
}
ArgumentNullException.ThrowIfNull(region);

if (string.IsNullOrEmpty(candidateNavigationContract))
{
throw new ArgumentNullException(nameof(candidateNavigationContract));
}

var contractCandidates = GetCandidatesFromRegionViews(region, candidateNavigationContract);
var contractCandidates = RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, candidateNavigationContract);

if (!contractCandidates.Any())
{
var registry = region.Container().Resolve<IRegionNavigationRegistry>();
var registration = registry.Registrations.FirstOrDefault(x => x.Type == ViewType.Region && (x.Name == candidateNavigationContract || x.View.Name == candidateNavigationContract || x.View.FullName == candidateNavigationContract));
if (registration is null)
{
GetCandidatesFromRegionViews(region, registration.View.FullName);
RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, registration.View.FullName);
}

return Array.Empty<VisualElement>();
return [];
}

return contractCandidates;
}

private IEnumerable<VisualElement> GetCandidatesFromRegionViews(IRegion region, string candidateNavigationContract)
private static IEnumerable<VisualElement> GetCandidatesFromRegionViews(IRegion region, string candidateNavigationContract)
{
return region.Views.OfType<VisualElement>().Where(v => ViewIsMatch(v.GetType(), candidateNavigationContract));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Prism.Common;
using Prism.Common;

namespace Prism.DryIoc.Maui.Tests.Mocks.ViewModels;

#pragma warning disable CS0067 // The event is never used because this is a Mock
public abstract class MockViewModelBase : IActiveAware, INavigationAware, IConfirmNavigation
{
private readonly IPageAccessor _pageAccessor;
Expand Down Expand Up @@ -49,3 +50,4 @@ public void OnNavigatedTo(INavigationParameters parameters)
Message = message;
}
}
#pragma warning restore CS0067 // The event is never used because this is a Mock
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


using System;
using System.Collections.Generic;
using Prism.Common;
Expand Down Expand Up @@ -78,7 +76,7 @@ public void CanRemoveValue()
list.Add("foo", value);
list.RemoveValue("foo", value);

Assert.Equal(0, list["foo"].Count);
Assert.Empty(list["foo"]);
}

[Fact]
Expand All @@ -90,7 +88,7 @@ public void CanRemoveValueFromAllLists()

list.RemoveValue(value);

Assert.Equal(0, list.Values.Count);
Assert.Empty(list.Values);
}

[Fact]
Expand Down Expand Up @@ -125,20 +123,19 @@ public void CanRemoveList()
bool removed = list.Remove("foo");

Assert.True(removed);
Assert.Equal(0, list.Keys.Count);
Assert.Empty(list.Keys);
}

[Fact]
public void CanSetList()
{
List<object> values = new List<object>();
values.Add(new object());
List<object> values = [new object()];
list.Add("foo", new object());
list.Add("foo", new object());

list["foo"] = values;

Assert.Equal(1, list["foo"].Count);
Assert.Single(list["foo"]);
}

[Fact]
Expand Down

0 comments on commit 2b9b78d

Please sign in to comment.