Skip to content

Commit

Permalink
Document the page navigation registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-- committed Jun 7, 2021
1 parent 51ab36d commit a555223
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Forms/Prism.Forms/Navigation/PageNavigationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@

namespace Prism.Navigation
{
/// <summary>
/// Represents page registration information
/// </summary>
public class PageNavigationInfo
{
/// <summary>
/// The unique name to registered Page
/// </summary>
public string Name { get; set; }

/// <summary>
/// The type of the registered Page
/// </summary>
public Type Type { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/Forms/Prism.Forms/Navigation/PageNavigationRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

namespace Prism.Navigation
{
/// <summary>
/// Maintains page navigation registrations.
/// </summary>
public static class PageNavigationRegistry
{
static Dictionary<string, PageNavigationInfo> _pageRegistrationCache = new Dictionary<string, PageNavigationInfo>();

/// <summary>
/// Registers a Page for navigation.
/// </summary>
/// <param name="name">The unique name to register with the Page.</param>
/// <param name="pageType">The type of Page to registe.r</param>
public static void Register(string name, Type pageType)
{
var info = new PageNavigationInfo
Expand All @@ -20,6 +28,11 @@ public static void Register(string name, Type pageType)
_pageRegistrationCache.Add(name, info);
}

/// <summary>
/// Gets the <see cref="PageNavigationInfo"/> for a given registration name.
/// </summary>
/// <param name="name">The registration name.</param>
/// <returns>The <see cref="PageNavigationInfo"/> instance for the given name if registered, null otherwise.</returns>
public static PageNavigationInfo GetPageNavigationInfo(string name)
{
if (_pageRegistrationCache.ContainsKey(name))
Expand All @@ -28,6 +41,11 @@ public static PageNavigationInfo GetPageNavigationInfo(string name)
return null;
}

/// <summary>
/// Gets the <see cref="PageNavigationInfo"/> for a given page type.
/// </summary>
/// <param name="pageType">The registration's type.</param>
/// <returns>The first <see cref="PageNavigationInfo"/> instance for the given type if registered, null otherwise.</returns>
public static PageNavigationInfo GetPageNavigationInfo(Type pageType)
{
foreach (var item in _pageRegistrationCache)
Expand All @@ -39,11 +57,19 @@ public static PageNavigationInfo GetPageNavigationInfo(Type pageType)
return null;
}

/// <summary>
/// Gets the type for a given registration name.
/// </summary>
/// <param name="name">The registration name.</param>
/// <returns>The type of the registration for the given name if registered, null otherwise</returns>
public static Type GetPageType(string name)
{
return GetPageNavigationInfo(name)?.Type;
}

/// <summary>
/// Clears the page registration cache.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void ClearRegistrationCache()
{
Expand Down

0 comments on commit a555223

Please sign in to comment.