1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

Routing - Added missing XAML comments to public types

This commit is contained in:
Robert 2023-07-27 20:16:02 +02:00
parent 66f263ff2a
commit 02798b6d6e
5 changed files with 98 additions and 10 deletions

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace Artemis.UI.Shared.Routing;
/// <summary>
/// Represents a registration for a route.
/// </summary>
public interface IRouterRegistration
{
/// <summary>
/// Gets the route associated with this registration.
/// </summary>
Route Route { get; }
/// <summary>
/// Gets the type of the view model associated with the route.
/// </summary>
Type ViewModel { get; }
/// <summary>
/// Gets or sets the child registrations of this route.
/// </summary>
List<IRouterRegistration> Children { get; set; }
}

View File

@ -1,7 +1,23 @@
namespace Artemis.UI.Shared.Routing.ParameterParsers;
/// <summary>
/// Represents a contract for parsing route parameters.
/// </summary>
public interface IRouteParameterParser
{
/// <summary>
/// Checks if the given segment matches the provided source.
/// </summary>
/// <param name="segment">The route segment to match.</param>
/// <param name="source">The source value to match against the route segment.</param>
/// <returns><see langword="true"/> if the segment matches the source; otherwise, <see langword="false"/>.</returns>
bool IsMatch(RouteSegment segment, string source);
/// <summary>
/// Gets the parameter value from the provided source value.
/// </summary>
/// <param name="segment">The route segment containing the parameter information.</param>
/// <param name="source">The source value from which to extract the parameter value.</param>
/// <returns>The extracted parameter value.</returns>
object GetValue(RouteSegment segment, string source);
}

View File

@ -3,15 +3,29 @@ using System.Linq;
namespace Artemis.UI.Shared.Routing;
/// <summary>
/// Represents a route at a certain path.
/// </summary>
public class Route
{
/// <summary>
/// Initializes a new instance of the <see cref="Route" /> class.
/// </summary>
/// <param name="path">The path of the route.</param>
public Route(string path)
{
Path = path;
Segments = path.Split('/').Select(s => new RouteSegment(s)).ToList();
}
/// <summary>
/// Gets the path of the route.
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the list of segments that makes up the path.
/// </summary>
public List<RouteSegment> Segments { get; }
/// <inheritdoc />

View File

@ -1,12 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Artemis.UI.Shared.Routing;
/// <summary>
/// Represents a registration for a route and its associated view model.
/// </summary>
/// <typeparam name="TViewModel">The type of the view model associated with the route.</typeparam>
public class RouteRegistration<TViewModel> : IRouterRegistration where TViewModel : ViewModelBase
{
/// <summary>
/// Initializes a new instance of the <see cref="RouteRegistration{TViewModel}" /> class.
/// </summary>
/// <param name="path">The path of the route.</param>
public RouteRegistration(string path)
{
Route = new Route(path);
@ -18,6 +24,9 @@ public class RouteRegistration<TViewModel> : IRouterRegistration where TViewMode
return $"{nameof(Route)}: {Route}, {nameof(ViewModel)}: {ViewModel}";
}
/// <summary>
/// Gets the route associated with this registration.
/// </summary>
public Route Route { get; }
/// <inheritdoc />
@ -25,12 +34,4 @@ public class RouteRegistration<TViewModel> : IRouterRegistration where TViewMode
/// <inheritdoc />
public List<IRouterRegistration> Children { get; set; } = new();
}
public interface IRouterRegistration
{
Route Route { get; }
Type ViewModel { get; }
List<IRouterRegistration> Children { get; set; }
}

View File

@ -4,10 +4,17 @@ using Artemis.UI.Shared.Routing.ParameterParsers;
namespace Artemis.UI.Shared.Routing;
/// <summary>
/// Represents a segment of a route.
/// </summary>
public partial class RouteSegment
{
private readonly IRouteParameterParser? _parameterParser;
/// <summary>
/// Initializes a new instance of the <see cref="RouteSegment"/> class.
/// </summary>
/// <param name="segment">The segment value.</param>
public RouteSegment(string segment)
{
Segment = segment;
@ -21,10 +28,26 @@ public partial class RouteSegment
}
}
/// <summary>
/// Gets the segment value.
/// </summary>
public string Segment { get; }
/// <summary>
/// Gets the parameter name if the segment is a parameterized segment; otherwise <see langword="null"/>.
/// </summary>
public string? Parameter { get; }
/// <summary>
/// Gets the type of the parameter if the segment is a parameterized segment; otherwise <see langword="null"/>.
/// </summary>
public string? ParameterType { get; }
/// <summary>
/// Checks if the segment matches the provided value.
/// </summary>
/// <param name="value">The value to compare with the segment.</param>
/// <returns><see langword="true"/> if the segment matches the value; otherwise, <see langword="false"/>.</returns>
public bool IsMatch(string value)
{
if (_parameterParser == null)
@ -32,6 +55,11 @@ public partial class RouteSegment
return _parameterParser.IsMatch(this, value);
}
/// <summary>
/// Gets the parameter value from the provided value.
/// </summary>
/// <param name="value">The value from which to extract the parameter value.</param>
/// <returns>The extracted parameter value.</returns>
public object? GetParameter(string value)
{
if (_parameterParser == null)
@ -58,6 +86,10 @@ public partial class RouteSegment
// Default to a string parser which just returns the segment as is
}
/// <summary>
/// Gets the regular expression used to identify parameterized segments in the route.
/// </summary>
/// <returns>The regular expression pattern.</returns>
[GeneratedRegex(@"\{(\w+):(\w+)\}")]
private static partial Regex ParameterRegex();
}