public class RouteManager { private JObject jsonObject = new JObject(); public void AddRoute(string webPath, string resourcePath) { jsonObject.AddChild(webPath, resourcePath); } public string GetResourcePathByRoute(string webPath) { var result = jsonObject.SelectToken($"$..[?(@=~/{webPath.Trim('/')}/ig)]"); if (result != null) { return result.Value<string>(); } return null; } }
本身写了个相似路由的功能,用到了Json,正则匹配比较方便web