mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
|
|
namespace Squidex.Web
|
|
{
|
|
public static class UrlHelperExtensions
|
|
{
|
|
private static class NameOf<T>
|
|
{
|
|
public static readonly string Controller;
|
|
|
|
static NameOf()
|
|
{
|
|
const string suffix = "Controller";
|
|
|
|
var name = typeof(T).Name;
|
|
|
|
if (name.EndsWith(suffix))
|
|
{
|
|
name = name.Substring(0, name.Length - suffix.Length);
|
|
}
|
|
|
|
Controller = name;
|
|
}
|
|
}
|
|
|
|
public static string Url<T>(this IUrlHelper urlHelper, Func<T, string> action, object values = null) where T : Controller
|
|
{
|
|
return urlHelper.Action(action(null), NameOf<T>.Controller, values);
|
|
}
|
|
|
|
public static string Url<T>(this Controller controller, Func<T, string> action, object values = null) where T : Controller
|
|
{
|
|
return controller.Url.Url(action, values);
|
|
}
|
|
}
|
|
}
|
|
|