Добавлено автоматические заполнение маршрутов для страниц

This commit is contained in:
2025-12-06 07:31:18 +03:00
parent d97fcaaa20
commit 07df710ce6
3 changed files with 55 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
namespace BotPages.Core.Routing;
using System.Reflection;
namespace BotPages.Core.Routing;
/// <summary>
/// Реестр маршрутов страниц.
@@ -26,4 +28,14 @@ internal sealed class RoutesRegistry
/// Получить снимок всех маршрутов.
/// </summary>
public IReadOnlyDictionary<string, Type> Snapshot() => _routes;
internal void Map(Type? type)
{
foreach(var attr in type.GetCustomAttributes<RouteAttribute>(inherit: true))
{
_routes.Add(attr.Template, type);
}
_routes.Add(type.FullName, type);
}
}