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