Files
mixtape/zero.Core/Extensions/RouteExtensions.cs
T

38 lines
866 B
C#
Raw Normal View History

2021-10-06 14:55:50 +02:00
using System;
using zero.Core.Routing;
2021-10-05 15:50:12 +02:00
namespace zero.Core.Extensions
{
public static class RouteExtensions
{
2021-10-06 14:55:50 +02:00
public static Route DependsOn(this Route route, params string[] ids)
2021-10-05 15:50:12 +02:00
{
2021-10-06 14:55:50 +02:00
route.Dependencies.AddRange(ids);
2021-10-05 15:50:12 +02:00
return route;
}
public static Route Param(this Route route, string key, object value)
{
route.Params[key] = value;
return route;
}
2021-10-06 14:55:50 +02:00
public static object Param(this Route route, string key)
{
return route.Params.TryGetValue(key, out object val) ? val : default;
}
public static T Param<T>(this Route route, string key)
{
return route.Params.GetValueOrDefault<T>(key);
}
[Obsolete]
2021-10-05 15:50:12 +02:00
public static Route Reference(this Route route, string id, string collection)
{
route.References.Add(new(id, collection));
return route;
}
}
}