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(); } return null; } }
自己写了个类似路由的功能,用到了Json,正则匹配比较方便