Skip to content

Commit c54631c

Browse files
committed
fix: add net9 again; wip router as ICollection
1 parent 596fe6f commit c54631c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/Routing/Router.SetRoute.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ public void MapHead ( string path, RouteAction action )
211211
#endregion
212212

213213
#region SetRoute methods
214+
215+
/// <summary>
216+
/// Defines the specified collection of routes.
217+
/// </summary>
218+
/// <param name="routes">The routes to be defined.</param>
219+
#if NET9_0_OR_GREATER
220+
public void SetRoutes ( params IEnumerable<Route> routes ) {
221+
#else
222+
public void SetRoutes ( params Route [] routes ) {
223+
#endif
224+
foreach (var route in routes)
225+
SetRoute ( route );
226+
}
227+
214228
/// <summary>
215229
/// Defines an route with their method, path and action function.
216230
/// </summary>

src/Routing/Router.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// File name: Router.cs
88
// Repository: https://github.com/sisk-http/core
99

10+
using System.Collections;
1011
using System.Diagnostics.CodeAnalysis;
1112
using System.Net;
1213
using System.Runtime.CompilerServices;
@@ -26,10 +27,13 @@ public ActionHandler ( Type matchingType, Func<object, HttpResponse> handler ) {
2627

2728

2829
namespace Sisk.Core.Routing {
30+
2931
/// <summary>
3032
/// Represents a collection of <see cref="Route"/> and main executor of actions in the <see cref="HttpServer"/>.
3133
/// </summary>
32-
public sealed partial class Router {
34+
[System.Diagnostics.CodeAnalysis.SuppressMessage ( "Naming", "CA1710:Identifiers should not have incorrect suffix",
35+
Justification = "Breaking change. Not going forward on this one." )]
36+
public sealed partial class Router : IReadOnlyCollection<Route> {
3337
internal sealed record RouterExecutionResult ( HttpResponse? Response, Route? Route, RouteMatchResult Result, Exception? Exception );
3438

3539
internal HttpServer? parentServer;
@@ -139,6 +143,9 @@ public Router ( IEnumerable<Route> routes )
139143
}
140144
} );
141145

146+
/// <inheritdoc/>
147+
public int Count => ((IReadOnlyCollection<Route>) _routesList).Count;
148+
142149
/// <summary>
143150
/// Gets all routes defined on this router instance.
144151
/// </summary>
@@ -269,6 +276,15 @@ void CheckForRouteCollisionsCore () {
269276
internal void FreeHttpServer () {
270277
parentServer = null;
271278
}
279+
280+
/// <inheritdoc/>
281+
public IEnumerator<Route> GetEnumerator () {
282+
return ((IEnumerable<Route>) _routesList).GetEnumerator ();
283+
}
284+
285+
IEnumerator IEnumerable.GetEnumerator () {
286+
return ((IEnumerable) _routesList).GetEnumerator ();
287+
}
272288
}
273289

274290
internal enum RouteMatchResult {

src/Sisk.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- supported frameworks -->
44
<PropertyGroup>
5-
<TargetFrameworks>net8.0</TargetFrameworks>
5+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
66
<RootNamespace>Sisk.Core</RootNamespace>
77
<Configurations>Debug;Release</Configurations>
88
</PropertyGroup>

0 commit comments

Comments
 (0)