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

43 lines
979 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;
}
2021-11-05 13:46:07 +01:00
public static Route DependsOn(this Route route, Route anotherRoute)
{
route.Dependencies.AddRange(anotherRoute.Dependencies);
foreach ((string key, object value) in anotherRoute.Params)
{
route.Params[key] = value;
}
return route;
}
2021-10-05 15:50:12 +02:00
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);
}
2021-10-05 15:50:12 +02:00
}
}