diff --git a/src/Forms/Prism.Forms/Common/UriParsingHelper.cs b/src/Forms/Prism.Forms/Common/UriParsingHelper.cs deleted file mode 100644 index 38e282287c..0000000000 --- a/src/Forms/Prism.Forms/Common/UriParsingHelper.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Collections.Generic; -using Prism.Dialogs; -using Prism.Navigation; - -namespace Prism.Common -{ - /// - /// Helper class for parsing instances. - /// - public static class UriParsingHelper - { - private static readonly char[] _pathDelimiter = { '/' }; - - public static Queue GetUriSegments(Uri uri) - { - var segmentStack = new Queue(); - - if (!uri.IsAbsoluteUri) - { - uri = EnsureAbsolute(uri); - } - - string[] segments = uri.PathAndQuery.Split(_pathDelimiter, StringSplitOptions.RemoveEmptyEntries); - foreach (var segment in segments) - { - segmentStack.Enqueue(Uri.UnescapeDataString(segment)); - } - - return segmentStack; - } - - public static string GetSegmentName(string segment) - { - return segment.Split('?')[0]; - } - - public static INavigationParameters GetSegmentParameters(string segment) - { - string query = string.Empty; - - if (string.IsNullOrWhiteSpace(segment)) - { - return new NavigationParameters(query); - } - - var indexOfQuery = segment.IndexOf('?'); - if (indexOfQuery > 0) - query = segment.Substring(indexOfQuery); - - return new NavigationParameters(query); - } - - public static INavigationParameters GetSegmentParameters(string uriSegment, INavigationParameters parameters) - { - var navParameters = UriParsingHelper.GetSegmentParameters(uriSegment); - - if (parameters != null) - { - foreach (KeyValuePair navigationParameter in parameters) - { - navParameters.Add(navigationParameter.Key, navigationParameter.Value); - } - } - - return navParameters; - } - - public static IDialogParameters GetSegmentDialogParameters(string segment) - { - string query = string.Empty; - - if (string.IsNullOrWhiteSpace(segment)) - { - return new DialogParameters(query); - } - - var indexOfQuery = segment.IndexOf('?'); - if (indexOfQuery > 0) - query = segment.Substring(indexOfQuery); - - return new DialogParameters(query); - } - - public static IDialogParameters GetSegmentParameters(string uriSegment, IDialogParameters parameters) - { - var dialogParameters = UriParsingHelper.GetSegmentDialogParameters(uriSegment); - - if (parameters != null) - { - foreach (KeyValuePair navigationParameter in parameters) - { - dialogParameters.Add(navigationParameter.Key, navigationParameter.Value); - } - } - - return dialogParameters; - } - - public static Uri EnsureAbsolute(Uri uri) - { - if (uri.IsAbsoluteUri) - { - return uri; - } - - if (!uri.OriginalString.StartsWith("/", StringComparison.Ordinal)) - { - return new Uri("http://localhost/" + uri, UriKind.Absolute); - } - return new Uri("http://localhost" + uri, UriKind.Absolute); - } - - 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); - } - } - } -} diff --git a/src/Maui/Prism.Maui/Common/UriParsingHelper.cs b/src/Maui/Prism.Maui/Common/UriParsingHelper.cs deleted file mode 100644 index a044daf4fd..0000000000 --- a/src/Maui/Prism.Maui/Common/UriParsingHelper.cs +++ /dev/null @@ -1,126 +0,0 @@ -using Prism.Dialogs; -using Prism.Navigation; - -namespace Prism.Common; - -/// -/// Helper class for parsing instances. -/// -public static class UriParsingHelper -{ - private static readonly char[] _pathDelimiter = { '/' }; - - public static Queue GetUriSegments(Uri uri) - { - var segmentStack = new Queue(); - - if (!uri.IsAbsoluteUri) - { - uri = EnsureAbsolute(uri); - } - - string[] segments = uri.PathAndQuery.Split(_pathDelimiter, StringSplitOptions.RemoveEmptyEntries); - foreach (var segment in segments) - { - segmentStack.Enqueue(Uri.UnescapeDataString(segment)); - } - - return segmentStack; - } - - public static string GetSegmentName(string segment) - { - return segment.Split('?')[0]; - } - - public static INavigationParameters GetSegmentParameters(string segment) - { - string query = string.Empty; - - if (string.IsNullOrWhiteSpace(segment)) - { - return new NavigationParameters(query); - } - - var indexOfQuery = segment.IndexOf('?'); - if (indexOfQuery > 0) - query = segment[indexOfQuery..]; - - return new NavigationParameters(query); - } - - public static INavigationParameters GetSegmentParameters(string uriSegment, INavigationParameters parameters) - { - var navParameters = UriParsingHelper.GetSegmentParameters(uriSegment); - - if (parameters != null) - { - foreach (KeyValuePair navigationParameter in parameters) - { - navParameters.Add(navigationParameter.Key, navigationParameter.Value); - } - } - - return navParameters; - } - - public static IDialogParameters GetSegmentDialogParameters(string segment) - { - string query = string.Empty; - - if (string.IsNullOrWhiteSpace(segment)) - { - return new DialogParameters(query); - } - - var indexOfQuery = segment.IndexOf('?'); - if (indexOfQuery > 0) - query = segment[indexOfQuery..]; - - return new DialogParameters(query); - } - - public static IDialogParameters GetSegmentParameters(string uriSegment, IDialogParameters parameters) - { - var dialogParameters = GetSegmentDialogParameters(uriSegment); - - if (parameters != null) - { - foreach (KeyValuePair navigationParameter in parameters) - { - dialogParameters.Add(navigationParameter.Key, navigationParameter.Value); - } - } - - return dialogParameters; - } - - public static Uri EnsureAbsolute(Uri uri) - { - if (uri.IsAbsoluteUri) - { - return uri; - } - - if (!uri.OriginalString.StartsWith("/", StringComparison.Ordinal)) - { - return new Uri("app://prismapp.maui/" + uri, UriKind.Absolute); - } - return new Uri("app://prismapp.maui" + uri, UriKind.Absolute); - } - - public static Uri Parse(string uri) - { - if (string.IsNullOrEmpty(uri)) - throw new ArgumentNullException(nameof(uri)); - - if (uri.StartsWith("/", StringComparison.Ordinal)) - { - return new Uri("app://prismapp.maui" + uri, UriKind.Absolute); - } - else - { - return new Uri(uri, UriKind.RelativeOrAbsolute); - } - } -} diff --git a/src/Prism.Core/Common/UriParsingHelper.cs b/src/Prism.Core/Common/UriParsingHelper.cs new file mode 100644 index 0000000000..f768ac1059 --- /dev/null +++ b/src/Prism.Core/Common/UriParsingHelper.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using Prism.Dialogs; +using Prism.Navigation; + +namespace Prism.Common +{ + /// + /// Helper class for parsing instances. + /// + public static class UriParsingHelper + { + private static readonly char[] _pathDelimiter = { '/' }; + + /// + /// Gets the Uri segments from a deep linked Navigation Uri + /// + /// A navigation . + /// A collection of strings for each navigation segment within the Navigation . + public static Queue GetUriSegments(Uri uri) + { + var segmentStack = new Queue(); + + if (!uri.IsAbsoluteUri) + { + uri = EnsureAbsolute(uri); + } + + string[] segments = uri.PathAndQuery.Split(_pathDelimiter, StringSplitOptions.RemoveEmptyEntries); + foreach (var segment in segments) + { + segmentStack.Enqueue(Uri.UnescapeDataString(segment)); + } + + return segmentStack; + } + + /// + /// Gets the Segment name from a Navigation Segment + /// + /// A Navigation Segment + /// The navigation segment name from the provided segment. + public static string GetSegmentName(string segment) + { + return segment.Split('?')[0]; + } + + /// + /// Gets the Segment Parameters from a Navigation Segment that may contain a querystring + /// + /// A navigation segment which may contain a querystring + /// The . + public static INavigationParameters GetSegmentParameters(string segment) + { + string query = string.Empty; + + if (string.IsNullOrWhiteSpace(segment)) + { + return new NavigationParameters(query); + } + + var indexOfQuery = segment.IndexOf('?'); + if (indexOfQuery > 0) + query = segment.Substring(indexOfQuery); + + return new NavigationParameters(query); + } + + /// + /// Gets Segment Parameters including those parameters from an existing collection. + /// + /// The segment + /// The existing . + /// The combined . + public static INavigationParameters GetSegmentParameters(string uriSegment, INavigationParameters parameters) + { + var navParameters = GetSegmentParameters(uriSegment); + + if (parameters != null) + { + foreach (KeyValuePair navigationParameter in parameters) + { + navParameters.Add(navigationParameter.Key, navigationParameter.Value); + } + } + + return navParameters; + } + + /// + /// Gets the from a specified segment + /// + /// A navigation segment which may contain a querystring. + /// The . + public static IDialogParameters GetSegmentDialogParameters(string segment) + { + string query = string.Empty; + + if (string.IsNullOrWhiteSpace(segment)) + { + return new DialogParameters(query); + } + + var indexOfQuery = segment.IndexOf('?'); + if (indexOfQuery > 0) + query = segment.Substring(indexOfQuery); + + return new DialogParameters(query); + } + + /// + /// Gets the combined from a specified segment and existing + /// + /// A navigation segment which may contain a querystring. + /// Existing . + /// + public static IDialogParameters GetSegmentParameters(string uriSegment, IDialogParameters parameters) + { + var dialogParameters = GetSegmentDialogParameters(uriSegment); + + if (parameters != null) + { + foreach (KeyValuePair navigationParameter in parameters) + { + dialogParameters.Add(navigationParameter.Key, navigationParameter.Value); + } + } + + return dialogParameters; + } + + /// + /// Gets the query part of . + /// + /// The Uri. + public static string GetQuery(Uri uri) + { + return EnsureAbsolute(uri).Query; + } + + /// + /// Gets the AbsolutePath part of . + /// + /// The Uri. + public static string GetAbsolutePath(Uri uri) + { + return EnsureAbsolute(uri).AbsolutePath; + } + + /// + /// Parses the query of into a dictionary. + /// + /// The URI. + public static INavigationParameters ParseQuery(Uri uri) + { + var query = GetQuery(uri); + + return new NavigationParameters(query); + } + + /// + /// Parses a uri string to a properly initialized Uri for Prism + /// + /// 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); + } + } + + /// + /// This will provide the existing if it is already Absolute, otherwise + /// it will build a new Absolute . + /// + /// The source . + /// An Absolute . + public static Uri EnsureAbsolute(Uri uri) + { + if (uri.IsAbsoluteUri) + { + 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); + } + } +} diff --git a/src/Wpf/Prism.Wpf/Common/UriParsingHelper.cs b/src/Wpf/Prism.Wpf/Common/UriParsingHelper.cs deleted file mode 100644 index e19ba60626..0000000000 --- a/src/Wpf/Prism.Wpf/Common/UriParsingHelper.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using Prism.Navigation; -using Prism.Regions; - -namespace Prism.Common -{ - /// - /// Helper class for parsing instances. - /// - public static class UriParsingHelper - { - /// - /// Gets the query part of . - /// - /// The Uri. - public static string GetQuery(Uri uri) - { - return EnsureAbsolute(uri).Query; - } - - /// - /// Gets the AbsolutePath part of . - /// - /// The Uri. - public static string GetAbsolutePath(Uri uri) - { - return EnsureAbsolute(uri).AbsolutePath; - } - - /// - /// Parses the query of into a dictionary. - /// - /// The URI. - public static INavigationParameters ParseQuery(Uri uri) - { - var query = GetQuery(uri); - - return new NavigationParameters(query); - } - - private static Uri EnsureAbsolute(Uri uri) - { - if (uri.IsAbsoluteUri) - { - 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); - } - } -}