diff --git a/src/Prism.Core/Common/ParametersBase.cs b/src/Prism.Core/Common/ParametersBase.cs index 077ff736af..3814e290ce 100644 --- a/src/Prism.Core/Common/ParametersBase.cs +++ b/src/Prism.Core/Common/ParametersBase.cs @@ -1,11 +1,8 @@ -using System; using System.Collections; -using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Text; - +#nullable enable namespace Prism.Common { /// @@ -13,7 +10,7 @@ namespace Prism.Common /// public abstract class ParametersBase : IParameters { - private readonly List> _entries = []; + private readonly List> _entries = []; /// /// Default constructor. @@ -51,7 +48,7 @@ protected ParametersBase(string query) } i++; } - string key = null; + string? key = null; string value; if (num4 >= 0) { @@ -75,7 +72,7 @@ protected ParametersBase(string query) /// /// The key for the value to be returned. /// The value of the parameter referenced by the key; otherwise null. - public object this[string key] + public object? this[string key] { get { @@ -108,7 +105,7 @@ public object this[string key] /// The key to reference this value in the parameters collection. /// The value of the parameter to store. public void Add(string key, object value) => - _entries.Add(new KeyValuePair(key, value)); + _entries.Add(new KeyValuePair(key, value)); /// /// Checks collection for presence of key. @@ -122,7 +119,7 @@ public bool ContainsKey(string key) => /// Gets an enumerator for the KeyValuePairs in parameter collection. /// /// Enumerator. - public IEnumerator> GetEnumerator() => + public IEnumerator> GetEnumerator() => _entries.GetEnumerator(); /// @@ -181,7 +178,7 @@ public override string ToString() queryBuilder.Append(Uri.EscapeDataString(kvp.Key)); queryBuilder.Append('='); - queryBuilder.Append(Uri.EscapeDataString(kvp.Value?.ToString() is string str ? str : string.Empty)); + queryBuilder.Append(Uri.EscapeDataString(kvp.Value?.ToString() ?? string.Empty)); } } @@ -193,7 +190,7 @@ public override string ToString() /// /// An IEnumerable of KeyValuePairs to add to the current parameter list. [EditorBrowsable(EditorBrowsableState.Never)] - public void FromParameters(IEnumerable> parameters) => + public void FromParameters(IEnumerable> parameters) => _entries.AddRange(parameters); } } diff --git a/src/Prism.Core/Common/ParametersExtensions.cs b/src/Prism.Core/Common/ParametersExtensions.cs index 2f6f56d1e9..c34b45895d 100644 --- a/src/Prism.Core/Common/ParametersExtensions.cs +++ b/src/Prism.Core/Common/ParametersExtensions.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.ComponentModel; @@ -156,13 +157,6 @@ private static bool TryGetValueInternal(KeyValuePair kvp, Type t public static bool ContainsKey(this IEnumerable> parameters, string key) => parameters.Any(x => string.Compare(x.Key, key, StringComparison.Ordinal) == 0); - private static object GetDefault(Type type) - { - if (type.IsValueType) - { - return Activator.CreateInstance(type); - } - return null; - } + private static object? GetDefault(Type type) => type.IsValueType ? Activator.CreateInstance(type) : null; } } diff --git a/src/Prism.Core/Common/UriParsingHelper.cs b/src/Prism.Core/Common/UriParsingHelper.cs index f768ac1059..8e9acb165d 100644 --- a/src/Prism.Core/Common/UriParsingHelper.cs +++ b/src/Prism.Core/Common/UriParsingHelper.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections.Generic; using Prism.Dialogs; using Prism.Navigation; +#nullable enable namespace Prism.Common { /// @@ -10,7 +9,7 @@ namespace Prism.Common /// public static class UriParsingHelper { - private static readonly char[] _pathDelimiter = { '/' }; + private static readonly char[] _pathDelimiter = ['/']; /// /// Gets the Uri segments from a deep linked Navigation Uri @@ -40,10 +39,7 @@ public static Queue GetUriSegments(Uri uri) /// /// A Navigation Segment /// The navigation segment name from the provided segment. - public static string GetSegmentName(string segment) - { - return segment.Split('?')[0]; - } + public static string GetSegmentName(string segment) => segment.Split('?')[0]; /// /// Gets the Segment Parameters from a Navigation Segment that may contain a querystring @@ -72,7 +68,7 @@ public static INavigationParameters GetSegmentParameters(string segment) /// The segment /// The existing . /// The combined . - public static INavigationParameters GetSegmentParameters(string uriSegment, INavigationParameters parameters) + public static INavigationParameters GetSegmentParameters(string uriSegment, INavigationParameters? parameters) { var navParameters = GetSegmentParameters(uriSegment); @@ -114,7 +110,7 @@ public static IDialogParameters GetSegmentDialogParameters(string segment) /// A navigation segment which may contain a querystring. /// Existing . /// - public static IDialogParameters GetSegmentParameters(string uriSegment, IDialogParameters parameters) + public static IDialogParameters GetSegmentParameters(string uriSegment, IDialogParameters? parameters) { var dialogParameters = GetSegmentDialogParameters(uriSegment); @@ -133,19 +129,13 @@ public static IDialogParameters GetSegmentParameters(string uriSegment, IDialogP /// Gets the query part of . /// /// The Uri. - public static string GetQuery(Uri uri) - { - return EnsureAbsolute(uri).Query; - } + public static string GetQuery(Uri uri) => EnsureAbsolute(uri).Query; /// /// Gets the AbsolutePath part of . /// /// The Uri. - public static string GetAbsolutePath(Uri uri) - { - return EnsureAbsolute(uri).AbsolutePath; - } + public static string GetAbsolutePath(Uri uri) => EnsureAbsolute(uri).AbsolutePath; /// /// Parses the query of into a dictionary. @@ -164,19 +154,7 @@ public static INavigationParameters ParseQuery(Uri uri) /// A uri string. /// A . /// Throws an when the string is null or empty. - public static Uri Parse(string uri) - { - if (uri == null) throw new ArgumentNullException(nameof(uri)); - - if (uri.StartsWith("/", StringComparison.Ordinal)) - { - return new Uri("http://localhost" + uri, UriKind.Absolute); - } - else - { - return new Uri(uri, UriKind.RelativeOrAbsolute); - } - } + public static Uri Parse(string uri) => uri.StartsWith("/", StringComparison.Ordinal) ? new Uri("http://localhost" + uri, UriKind.Absolute) : new Uri(uri, UriKind.RelativeOrAbsolute); /// /// This will provide the existing if it is already Absolute, otherwise @@ -191,11 +169,7 @@ public static Uri EnsureAbsolute(Uri uri) return uri; } - if ((uri != null) && !uri.OriginalString.StartsWith("/", StringComparison.Ordinal)) - { - return new Uri("http://localhost/" + uri, UriKind.Absolute); - } - return new Uri("http://localhost" + uri, UriKind.Absolute); + return !uri.OriginalString.StartsWith("/", StringComparison.Ordinal) ? new Uri("http://localhost/" + uri, UriKind.Absolute) : new Uri("http://localhost" + uri, UriKind.Absolute); } } } diff --git a/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs b/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs index a39e5d1750..ef509897fd 100644 --- a/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs +++ b/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs @@ -1,8 +1,7 @@ -using System; -using Prism.Common; +using Prism.Common; namespace Prism.Maui.Tests.Fixtures.Common; - +#nullable enable public class UriParsingHelperFixture { const string _relativeUri = "MainPage?id=3&name=dan"; @@ -14,7 +13,7 @@ public class UriParsingHelperFixture [Fact] public void ParametersParsedFromNullSegment() { - var parameters = UriParsingHelper.GetSegmentParameters(null); + var parameters = UriParsingHelper.GetSegmentParameters(null!); Assert.NotNull(parameters); } @@ -62,7 +61,7 @@ public void ParametersParsedFromNavigationParametersInRelativeUri() { "name", "dan" } }; - var parameters = UriParsingHelper.GetSegmentParameters("MainPage" + navParameters.ToString()); + var parameters = UriParsingHelper.GetSegmentParameters("MainPage" + navParameters); Assert.NotEmpty(parameters); @@ -82,7 +81,7 @@ public void ParametersParsedFromNavigationParametersInAbsoluteUri() { "name", "dan" } }; - var parameters = UriParsingHelper.GetSegmentParameters("http://www.dansiegel.net/MainPage" + navParameters.ToString()); + var parameters = UriParsingHelper.GetSegmentParameters("http://www.dansiegel.net/MainPage" + navParameters); Assert.NotEmpty(parameters); @@ -177,7 +176,7 @@ public void EnsureAbsoluteUriForAbsoluteUri() [Fact] public void ParseForNull() { - var actual = Assert.Throws(() => UriParsingHelper.Parse(null)); + var actual = Assert.Throws(() => UriParsingHelper.Parse(null!)); Assert.NotNull(actual); Assert.Equal("uri", actual.ParamName); } diff --git a/tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs b/tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs index eb25cc801e..294ca98de6 100644 --- a/tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs +++ b/tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; using Prism.Common; using Xunit; -namespace Prism.Wpf.Tests +namespace Prism.Core.Tests.Common { public class ListDictionaryFixture diff --git a/tests/Prism.Core.Tests/Common/Mocks/MockEnum.cs b/tests/Prism.Core.Tests/Common/Mocks/MockEnum.cs index 74ebae993b..7e952e91f7 100644 --- a/tests/Prism.Core.Tests/Common/Mocks/MockEnum.cs +++ b/tests/Prism.Core.Tests/Common/Mocks/MockEnum.cs @@ -1,4 +1,4 @@ -namespace Prism.Tests.Common.Mocks +namespace Prism.Core.Tests.Common.Mocks { internal enum MockEnum { diff --git a/tests/Prism.Core.Tests/Common/Mocks/MockParameters.cs b/tests/Prism.Core.Tests/Common/Mocks/MockParameters.cs index 671f990144..e8eb52bc64 100644 --- a/tests/Prism.Core.Tests/Common/Mocks/MockParameters.cs +++ b/tests/Prism.Core.Tests/Common/Mocks/MockParameters.cs @@ -1,10 +1,10 @@ using Prism.Common; -namespace Prism.Tests.Common.Mocks +namespace Prism.Core.Tests.Common.Mocks { internal class MockParameters : ParametersBase { - public MockParameters() : base() { } + public MockParameters() { } public MockParameters(string query) : base(query) { } } } diff --git a/tests/Prism.Core.Tests/Common/MulticastExceptionHandlerFixture.cs b/tests/Prism.Core.Tests/Common/MulticastExceptionHandlerFixture.cs index d5b7026fcf..dde56ef560 100644 --- a/tests/Prism.Core.Tests/Common/MulticastExceptionHandlerFixture.cs +++ b/tests/Prism.Core.Tests/Common/MulticastExceptionHandlerFixture.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using Prism.Common; +using Prism.Common; using Xunit; namespace Prism.Core.Tests.Common; diff --git a/tests/Prism.Core.Tests/Common/ParametersFixture.cs b/tests/Prism.Core.Tests/Common/ParametersFixture.cs index abd2aa8cf0..caeae3509a 100644 --- a/tests/Prism.Core.Tests/Common/ParametersFixture.cs +++ b/tests/Prism.Core.Tests/Common/ParametersFixture.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; -using System.Linq; -using Prism.Tests.Common.Mocks; +#nullable enable +using Prism.Core.Tests.Common.Mocks; using Xunit; -namespace Prism.Tests.Common +namespace Prism.Core.Tests.Common { public class ParametersFixture { @@ -28,7 +27,7 @@ public void GetValuesOfT() { var parameters = new MockParameters("mock=Foo&mock=2&mock=Fizz"); - IEnumerable values = default; + IEnumerable values = Enumerable.Empty(); var ex = Record.Exception(() => values = parameters.GetValues("mock")); Assert.Null(ex);