routing
routing copied to clipboard
Bug RouteExtensions.Concatenate
public static Route Concatenate(this Route route1, Route route2, bool clone) the parameter clone is never used resulting in new instances always being in the concatenated route.
The fix would be to NOT Clone the route before assigning to the result if clone was false
Consider also a better api...
/// <summary>
/// Concatenates all the given routes or returns an error when `one` of the routes cannot be concatenated (if <paramref name="skipInvalid"/> is <see langword="false"/>).
/// </summary>
/// <param name="routes"></param>
/// <param name="skipInvalid">indicates if the method should skip or thow, defaults to <see langword="true" /> </param>
/// <returns>The resulting <see cref="Result<Route>"/> which is built from <paramref name="routes"/>, or the <see cref="Result<Route>"/> which indicates which route in <paramref name="routes"/> was invalid</returns>
/// <remarks>
/// Todo, This method sould out the errors there should be TryConcatenate, think of how corrections should be performed... WRT to performance
/// </remarks>
public static Result<Route> Concatenate(this IEnumerable<Result<Route>> routes, bool skipInvalid = true)
{
Route route = null;
var r = 0;
foreach (var localRoute in routes)
{
if (localRoute.IsError && false == skipInvalid)
{
return new Result<Route>($"Route at index {r} is in error: {localRoute.ErrorMessage}");
}
route = route == null ? localRoute.Value : route.Concatenate(localRoute.Value);
++r;
}
return new Result<Route>(route);
}