{"id":331955,"date":"2022-04-15T03:00:07","date_gmt":"2022-04-15T03:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=331955"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=331955","title":{"rendered":"<span>Roslyn-\u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0438\u0437 Regex \u0432 \u043d\u043e\u0432\u044b\u0439 Regex Source Generator<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/habr.com\/ru\/post\/503172\/\" rel=\"noopener noreferrer nofollow\">Source generators<\/a> (\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430) \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b Roslyn, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432 .NET 5. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.  <\/p>\n<p>\u0412 .NET 7 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e source generator. \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432: <\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 regex \u2014 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0434\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0434 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d. \u0421\u0435\u0439\u0447\u0430\u0441 (\u0432 .NET 7 Preview 3) \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 regex source generator \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0442\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c <code>RegexOptions.Compiled<\/code>, \u043d\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a iOS, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>Regex.IsMatch(value, pattern)<\/code> \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0438\u043c\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442, \u0447\u0435\u043c\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c \u0438 \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 regex, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 self-contained application, \u043a\u043e\u0433\u0434\u0430 .net runtime \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/deploying\/trimming\/trim-self-contained\" rel=\"noopener noreferrer nofollow\">\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0439<\/a> \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043d\u0438\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438!<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0445 \u043f\u0440\u0438\u0435\u043c\u0430\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0438\u0442\u0430\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 (\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f (regex pattern, \u043e\u043f\u0446\u0438\u0438 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442) \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"cs\">public static bool IsLowercase(string value) {     \/\/ \u2714\ufe0f pattern \u0437\u0430\u0434\u0430\u043d \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439     \/\/ => \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 source generator     var lowercaseLettersRegex = new Regex(\"[a-z]+\");     return lowercaseLettersRegex.IsMatch(\"abc\"); }  public static bool IsLowercase(string value) {     \/\/ \u2714\ufe0f pattern, \u043e\u043f\u0446\u0438\u0438 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0437\u0430\u0434\u0430\u043d\u044b \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439     \/\/ => \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 source generator     return Regex.IsMatch(value, \"[a-z]+\", RegexOptions.CultureInvariant, TimeSpan.FromSeconds(1)); }  public static bool Match(string value, string pattern) {     \/\/ \u274c pattern \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c      \/\/ => \u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c source generator     return Regex.IsMatch(value, pattern); }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 source generator \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e partial-\u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>[RegexGenerator]<\/code>. \u0422\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u0430\u043a <code>partial<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ Source Generator \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 [RegexGenerator(\"^[a-z]+$\", RegexOptions.CultureInvariant, matchTimeoutMilliseconds: 1000)] private static partial Regex LowercaseLettersRegex();  public static bool IsLowercase(string value) {     return LowercaseLettersRegex().IsMatch(value); }<\/code><\/pre>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 partial-\u043a\u043b\u0430\u0441\u0441\u0435 \u0447\u0435\u0440\u0435\u0437 Solution explorer \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043d\u0435\u043c\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 &#171;Go to definition&#187;:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2f5\/d44\/de1\/2f5d44de1813b790513f5a110b3a9765.png\" width=\"668\" height=\"628\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2f5\/d44\/de1\/2f5d44de1813b790513f5a110b3a9765.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/86b\/afb\/365\/86bafb365b810dc89579555177a819d1.png\" width=\"941\" height=\"351\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/86b\/afb\/365\/86bafb365b810dc89579555177a819d1.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Regex \u0432 Source Generator<\/h3>\n<p>NuGet-\u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/www.nuget.org\/packages\/Meziantou.Analyzer\/\" rel=\"noopener noreferrer nofollow\"><u>Meziantou.Analyzer<\/u><\/a>\u00a0\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u0432 Source Generator, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 Regex \u0432 partail-\u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>[RegexGenerator]<\/code>. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code class=\"bash\">dotnet add package Meziantou.Analyzer<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u043e <a href=\"https:\/\/github.com\/meziantou\/Meziantou.Analyzer\/blob\/main\/docs\/Rules\/MA0110.md\" rel=\"noopener noreferrer nofollow\"><u>MA0110<\/u><\/a> \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u043e \u0432\u0441\u0435\u0445 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 (code fix) \u0438\u0437 <code>Regex<\/code> \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cdc\/d70\/01d\/cdcd7001d7e0190503f93ecd24e0aa55.gif\" width=\"600\" height=\"292\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cdc\/d70\/01d\/cdcd7001d7e0190503f93ecd24e0aa55.gif\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0421\u0442\u0430\u0442\u0443\u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438<\/h2>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c regex source generator \u0438 Meziantou.Analyzer \u043c\u043e\u0436\u043d\u043e \u0441 .NET 7 (\u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Preview 1) \u0438 C# 11.<\/p>\n<\/li>\n<li>\n<p>Rider \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 C# 11 \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 2022.1 EAP \u2014 \u043a\u043e\u0434 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043a \u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 Go to definition, \u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u00a0Visual Studio 17.2 Preview 1 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 .NET 7 \u0438 C# 11.<\/p>\n<\/li>\n<\/ul>\n<h2>\u041b\u043e\u0436\u043a\u0430 \u0434\u0451\u0433\u0442\u044f \u2014 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/h2>\n<p>\u041f\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e regex source generator <a href=\"https:\/\/www.meziantou.net\/regex-source-generator.htm\" rel=\"noopener noreferrer nofollow\">\u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u2014 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 self-contained application, \u043d\u043e \u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0434\u0435\u0431\u0430\u0433\u0430 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code class=\"cs\">[RegexGenerator(@\"(\\+7|7|8)?[\\s\\-]?\\(?[489][0-9]{2}\\)?[\\s\\-]?[0-9]{3}[\\s\\-]?[0-9]{2}[\\s\\-]?[0-9]{2}\"] private partial Regex RussianPhoneNumberRegex();  public string? FindPhoneNumber(string text) {     var match = RussianPhoneNumberRegex().Match(text);     return match.Success ? match.Value : null; }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>362 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">\/\/ &lt;auto-generated\/> #nullable enable #pragma warning disable CS0162 \/\/ Unreachable code #pragma warning disable CS0164 \/\/ Unreferenced label #pragma warning disable CS0219 \/\/ Variable assigned but never used  namespace RegexGeneratorExample {     partial class RegexContainer     {         [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Text.RegularExpressions.Generator\", \"7.0.6.17504\")]         private partial global::System.Text.RegularExpressions.Regex RussianPhoneNumberRegex() => global::System.Text.RegularExpressions.Generated.__2b701bf8.RussianPhoneNumberRegex_0.Instance;     } }  namespace System.Text.RegularExpressions.Generated {     using System;     using System.CodeDom.Compiler;     using System.Collections;     using System.ComponentModel;     using System.Globalization;     using System.Runtime.CompilerServices;     using System.Text.RegularExpressions;     using System.Threading;      [GeneratedCodeAttribute(\"System.Text.RegularExpressions.Generator\", \"7.0.6.17504\")]     [EditorBrowsable(EditorBrowsableState.Never)]     internal static class __2b701bf8     {         \/\/\/ &lt;summary>Custom &lt;see cref=\"Regex\"\/>-derived type for the RussianPhoneNumberRegex method.&lt;\/summary>         internal sealed class RussianPhoneNumberRegex_0 : Regex         {             \/\/\/ &lt;summary>Cached, thread-safe singleton instance.&lt;\/summary>             internal static readonly RussianPhoneNumberRegex_0 Instance = new();                      \/\/\/ &lt;summary>Initializes the instance.&lt;\/summary>             private RussianPhoneNumberRegex_0()             {                 base.pattern = \"(\\\\+7|7|8)?[\\\\s\\\\-]?\\\\(?[489][0-9]{2}\\\\)?[\\\\s\\\\-]?[0-9]{3}[\\\\s\\\\-]?[0-9]{2}[\\\\s\\\\-]?[0-9]{2}\";                 base.roptions = RegexOptions.CultureInvariant;                 base.internalMatchTimeout = TimeSpan.FromMilliseconds(1000);                 base.factory = new RunnerFactory();                 base.capsize = 2;             }                      \/\/\/ &lt;summary>Provides a factory for creating &lt;see cref=\"RegexRunner\"\/> instances to be used by methods on &lt;see cref=\"Regex\"\/>.&lt;\/summary>             private sealed class RunnerFactory : RegexRunnerFactory             {                 \/\/\/ &lt;summary>Creates an instance of a &lt;see cref=\"RegexRunner\"\/> used by methods on &lt;see cref=\"Regex\"\/>.&lt;\/summary>                 protected override RegexRunner CreateInstance() => new Runner();                              \/\/\/ &lt;summary>Provides the runner that contains the custom logic implementing the specified regular expression.&lt;\/summary>                 private sealed class Runner : RegexRunner                 {                     \/\/ Description:                     \/\/ \u25cb Optional (greedy).                     \/\/     \u25cb 1st capture group.                     \/\/         \u25cb Match with 2 alternative expressions.                     \/\/             \u25cb Match the string \"+7\".                     \/\/             \u25cb Match a character in the set [78].                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '(' atomically, optionally.                     \/\/ \u25cb Match a character in the set [489].                     \/\/ \u25cb Match '0' through '9' exactly 2 times.                     \/\/ \u25cb Match ')' atomically, optionally.                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '0' through '9' exactly 3 times.                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '0' through '9' exactly 2 times.                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '0' through '9' exactly 2 times.                                  \/\/\/ &lt;summary>Scan the &lt;paramref name=\"inputSpan\"\/> starting from base.runtextstart for the next match.&lt;\/summary>                     \/\/\/ &lt;param name=\"inputSpan\">The text being scanned by the regular expression.&lt;\/param>                     protected override void Scan(ReadOnlySpan&lt;char> inputSpan)                     {                         \/\/ Search until we can't find a valid starting position, we find a match, or we reach the end of the input.                         while (TryFindNextPossibleStartingPosition(inputSpan))                         {                             base.CheckTimeout();                             if (TryMatchAtCurrentPosition(inputSpan) || base.runtextpos == inputSpan.Length)                             {                                 return;                             }                                                          base.runtextpos++;                         }                     }                                  \/\/\/ &lt;summary>Search &lt;paramref name=\"inputSpan\"\/> starting from base.runtextpos for the next location a match could possibly start.&lt;\/summary>                     \/\/\/ &lt;param name=\"inputSpan\">The text being scanned by the regular expression.&lt;\/param>                     \/\/\/ &lt;returns>true if a possible match was found; false if no more matches are possible.&lt;\/returns>                     private bool TryFindNextPossibleStartingPosition(ReadOnlySpan&lt;char> inputSpan)                     {                         int pos = base.runtextpos;                         char ch;                                                  \/\/ Validate that enough room remains in the input to match.                         \/\/ Any possible match is at least 10 characters.                         if (pos &lt;= inputSpan.Length - 10)                         {                             \/\/ The pattern begins with a character in the set [(+-47-9\\s].                             \/\/ Find the next occurrence. If it can't be found, there's no match.                             ReadOnlySpan&lt;char> span = inputSpan.Slice(pos);                             for (int i = 0; i &lt; span.Length; i++)                             {                                 if (((ch = span[i]) &lt; 128 ? (\"\u3e00\\0\u2901\u0390\\0\\0\\0\\0\"[ch >> 4] &amp; (1 &lt;&lt; (ch &amp; 0xF))) != 0 : RegexRunner.CharInClass((char)ch, \"\\0\\n\\u0001()+,-.457:d\")))                                 {                                     base.runtextpos = pos + i;                                     return true;                                 }                             }                         }                                                  \/\/ No match found.                         base.runtextpos = inputSpan.Length;                         return false;                     }                                  \/\/\/ &lt;summary>Determine whether &lt;paramref name=\"inputSpan\"\/> at base.runtextpos is a match for the regular expression.&lt;\/summary>                     \/\/\/ &lt;param name=\"inputSpan\">The text being scanned by the regular expression.&lt;\/param>                     \/\/\/ &lt;returns>true if the regular expression matches at the current position; otherwise, false.&lt;\/returns>                     private bool TryMatchAtCurrentPosition(ReadOnlySpan&lt;char> inputSpan)                     {                         int pos = base.runtextpos;                         int matchStart = pos;                         int loopTimeoutCounter = 0;                         char ch;                         int loop_iteration = 0, loop_starting_pos = 0;                         int stackpos = 0;                         ReadOnlySpan&lt;char> slice = inputSpan.Slice(pos);                                                  \/\/ Optional (greedy).                         \/\/{                             loop_iteration = 0;                             loop_starting_pos = pos;                                                          LoopBody:                             if (++loopTimeoutCounter == 2048)                             {                                 loopTimeoutCounter = 0;                                 base.CheckTimeout();                             }                                                          Utilities.StackPush3(ref base.runstack!, ref stackpos, base.Crawlpos(), loop_starting_pos, pos);                                                          loop_starting_pos = pos;                             loop_iteration++;                                                          \/\/ 1st capture group.                             \/\/{                                 int capture_starting_pos = pos;                                                                  \/\/ Match with 2 alternative expressions.                                 \/\/{                                     if (slice.IsEmpty)                                     {                                         goto LoopIterationNoMatch;                                     }                                                                          switch (slice[0])                                     {                                         case '+':                                             \/\/ Match '7'.                                             if ((uint)slice.Length &lt; 2 || slice[1] != '7')                                             {                                                 goto LoopIterationNoMatch;                                             }                                                                                          pos += 2;                                             slice = inputSpan.Slice(pos);                                             break;                                                                                      case '7' or '8':                                             pos++;                                             slice = inputSpan.Slice(pos);                                             break;                                                                                      default:                                             goto LoopIterationNoMatch;                                     }                                 \/\/}                                                                  base.Capture(1, capture_starting_pos, pos);                             \/\/}                                                          if (pos != loop_starting_pos &amp;&amp; loop_iteration == 0)                             {                                 goto LoopBody;                             }                             goto LoopEnd;                                                          LoopIterationNoMatch:                             loop_iteration--;                             if (loop_iteration &lt; 0)                             {                                 UncaptureUntil(0);                                 return false; \/\/ The input didn't match.                             }                             Utilities.StackPop2(base.runstack, ref stackpos, out pos, out loop_starting_pos);                             UncaptureUntil(base.runstack![--stackpos]);                             slice = inputSpan.Slice(pos);                             LoopEnd:;                         \/\/}                                                  \/\/ Match a character in the set [-\\s] atomically, optionally.                         {                             if (!slice.IsEmpty &amp;&amp; ((ch = slice[0]) &lt; 128 ? (\"\u3e00\\0\u2001\\0\\0\\0\\0\\0\"[ch >> 4] &amp; (1 &lt;&lt; (ch &amp; 0xF))) != 0 : RegexRunner.CharInClass((char)ch, \"\\0\\u0002\\u0001-.d\")))                             {                                 slice = slice.Slice(1);                                 pos++;                             }                         }                                                  \/\/ Match '(' atomically, optionally.                         {                             if (!slice.IsEmpty &amp;&amp; slice[0] == '(')                             {                                 slice = slice.Slice(1);                                 pos++;                             }                         }                                                  if ((uint)slice.Length &lt; 3 ||                             (((ch = slice[0]) != '4') &amp; (ch != '8') &amp; (ch != '9')) || \/\/ Match a character in the set [489].                             (((uint)slice[1]) - '0' > (uint)('9' - '0')) || \/\/ Match '0' through '9' exactly 2 times.                             (((uint)slice[2]) - '0' > (uint)('9' - '0')))                         {                             goto LoopIterationNoMatch;                         }                                                  \/\/ Match ')' atomically, optionally.                         {                             if ((uint)slice.Length > (uint)3 &amp;&amp; slice[3] == ')')                             {                                 slice = slice.Slice(1);                                 pos++;                             }                         }                                                  \/\/ Match a character in the set [-\\s] atomically, optionally.                         {                             if ((uint)slice.Length > (uint)3 &amp;&amp; ((ch = slice[3]) &lt; 128 ? (\"\u3e00\\0\u2001\\0\\0\\0\\0\\0\"[ch >> 4] &amp; (1 &lt;&lt; (ch &amp; 0xF))) != 0 : RegexRunner.CharInClass((char)ch, \"\\0\\u0002\\u0001-.d\")))                             {                                 slice = slice.Slice(1);                                 pos++;                             }                         }                                                  \/\/ Match '0' through '9' exactly 3 times.                         {                             if ((uint)slice.Length &lt; 6 ||                                 (((uint)slice[3]) - '0' > (uint)('9' - '0')) ||                                 (((uint)slice[4]) - '0' > (uint)('9' - '0')) ||                                 (((uint)slice[5]) - '0' > (uint)('9' - '0')))                             {                                 goto LoopIterationNoMatch;                             }                         }                                                  \/\/ Match a character in the set [-\\s] atomically, optionally.                         {                             if ((uint)slice.Length > (uint)6 &amp;&amp; ((ch = slice[6]) &lt; 128 ? (\"\u3e00\\0\u2001\\0\\0\\0\\0\\0\"[ch >> 4] &amp; (1 &lt;&lt; (ch &amp; 0xF))) != 0 : RegexRunner.CharInClass((char)ch, \"\\0\\u0002\\u0001-.d\")))                             {                                 slice = slice.Slice(1);                                 pos++;                             }                         }                                                  \/\/ Match '0' through '9' exactly 2 times.                         {                             if ((uint)slice.Length &lt; 8 ||                                 (((uint)slice[6]) - '0' > (uint)('9' - '0')) ||                                 (((uint)slice[7]) - '0' > (uint)('9' - '0')))                             {                                 goto LoopIterationNoMatch;                             }                         }                                                  \/\/ Match a character in the set [-\\s] atomically, optionally.                         {                             if ((uint)slice.Length > (uint)8 &amp;&amp; ((ch = slice[8]) &lt; 128 ? (\"\u3e00\\0\u2001\\0\\0\\0\\0\\0\"[ch >> 4] &amp; (1 &lt;&lt; (ch &amp; 0xF))) != 0 : RegexRunner.CharInClass((char)ch, \"\\0\\u0002\\u0001-.d\")))                             {                                 slice = slice.Slice(1);                                 pos++;                             }                         }                                                  \/\/ Match '0' through '9' exactly 2 times.                         {                             if ((uint)slice.Length &lt; 10 ||                                 (((uint)slice[8]) - '0' > (uint)('9' - '0')) ||                                 (((uint)slice[9]) - '0' > (uint)('9' - '0')))                             {                                 goto LoopIterationNoMatch;                             }                         }                                                  \/\/ The input matched.                         pos += 10;                         base.runtextpos = pos;                         base.Capture(0, matchStart, pos);                         return true;                                                  \/\/ &lt;summary>Undo captures until it reaches the specified capture position.&lt;\/summary>                         [MethodImpl(MethodImplOptions.AggressiveInlining)]                         void UncaptureUntil(int capturePosition)                         {                             while (base.Crawlpos() > capturePosition)                             {                                 base.Uncapture();                             }                         }                     }                 }             }          }                  private static class Utilities         {             \/\/ &lt;summary>Pushes 3 values onto the backtracking stack.&lt;\/summary>             [MethodImpl(MethodImplOptions.AggressiveInlining)]             internal static void StackPush3(ref int[] stack, ref int pos, int arg0, int arg1, int arg2)             {                 \/\/ If there's space available for all 3 values, store them.                 int[] s = stack;                 int p = pos;                 if ((uint)(p + 2) &lt; (uint)s.Length)                 {                     s[p] = arg0;                     s[p + 1] = arg1;                     s[p + 2] = arg2;                     pos += 3;                     return;                 }                              \/\/ Otherwise, resize the stack to make room and try again.                 WithResize(ref stack, ref pos, arg0, arg1, arg2);                              \/\/ &lt;summary>Resize the backtracking stack array and push 3 values onto the stack.&lt;\/summary>                 [MethodImpl(MethodImplOptions.NoInlining)]                 static void WithResize(ref int[] stack, ref int pos, int arg0, int arg1, int arg2)                 {                     Array.Resize(ref stack, (pos + 2) * 2);                     StackPush3(ref stack, ref pos, arg0, arg1, arg2);                 }             }                          \/\/ &lt;summary>Pops 2 values from the backtracking stack.&lt;\/summary>             [MethodImpl(MethodImplOptions.AggressiveInlining)]             internal static void StackPop2(int[] stack, ref int pos, out int arg0, out int arg1)             {                 arg0 = stack[--pos];                 arg1 = stack[--pos];             }                      }     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/661089\/\"> https:\/\/habr.com\/ru\/post\/661089\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/habr.com\/ru\/post\/503172\/\" rel=\"noopener noreferrer nofollow\">Source generators<\/a> (\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430) \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b Roslyn, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432 .NET 5. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.  <\/p>\n<p>\u0412 .NET 7 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e source generator. \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432: <\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 regex \u2014 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0434\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0434 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d. \u0421\u0435\u0439\u0447\u0430\u0441 (\u0432 .NET 7 Preview 3) \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 regex source generator \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0442\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c <code>RegexOptions.Compiled<\/code>, \u043d\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a iOS, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>Regex.IsMatch(value, pattern)<\/code> \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0438\u043c\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442, \u0447\u0435\u043c\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c \u0438 \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 regex, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 self-contained application, \u043a\u043e\u0433\u0434\u0430 .net runtime \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/deploying\/trimming\/trim-self-contained\" rel=\"noopener noreferrer nofollow\">\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0439<\/a> \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043d\u0438\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438!<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0445 \u043f\u0440\u0438\u0435\u043c\u0430\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0438\u0442\u0430\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 (\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f (regex pattern, \u043e\u043f\u0446\u0438\u0438 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442) \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"cs\">public static bool IsLowercase(string value) {     \/\/ \u2714\ufe0f pattern \u0437\u0430\u0434\u0430\u043d \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439     \/\/ => \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 source generator     var lowercaseLettersRegex = new Regex(\"[a-z]+\");     return lowercaseLettersRegex.IsMatch(\"abc\"); }  public static bool IsLowercase(string value) {     \/\/ \u2714\ufe0f pattern, \u043e\u043f\u0446\u0438\u0438 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0437\u0430\u0434\u0430\u043d\u044b \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439     \/\/ => \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 source generator     return Regex.IsMatch(value, \"[a-z]+\", RegexOptions.CultureInvariant, TimeSpan.FromSeconds(1)); }  public static bool Match(string value, string pattern) {     \/\/ \u274c pattern \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c      \/\/ => \u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c source generator     return Regex.IsMatch(value, pattern); }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 source generator \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e partial-\u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>[RegexGenerator]<\/code>. \u0422\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u0430\u043a <code>partial<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ Source Generator \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 [RegexGenerator(\"^[a-z]+$\", RegexOptions.CultureInvariant, matchTimeoutMilliseconds: 1000)] private static partial Regex LowercaseLettersRegex();  public static bool IsLowercase(string value) {     return LowercaseLettersRegex().IsMatch(value); }<\/code><\/pre>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 partial-\u043a\u043b\u0430\u0441\u0441\u0435 \u0447\u0435\u0440\u0435\u0437 Solution explorer \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043d\u0435\u043c\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 &#171;Go to definition&#187;:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Regex \u0432 Source Generator<\/h3>\n<p>NuGet-\u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/www.nuget.org\/packages\/Meziantou.Analyzer\/\" rel=\"noopener noreferrer nofollow\"><u>Meziantou.Analyzer<\/u><\/a>\u00a0\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u0432 Source Generator, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 Regex \u0432 partail-\u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>[RegexGenerator]<\/code>. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code class=\"bash\">dotnet add package Meziantou.Analyzer<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u043e <a href=\"https:\/\/github.com\/meziantou\/Meziantou.Analyzer\/blob\/main\/docs\/Rules\/MA0110.md\" rel=\"noopener noreferrer nofollow\"><u>MA0110<\/u><\/a> \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u043e \u0432\u0441\u0435\u0445 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 (code fix) \u0438\u0437 <code>Regex<\/code> \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0421\u0442\u0430\u0442\u0443\u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438<\/h2>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c regex source generator \u0438 Meziantou.Analyzer \u043c\u043e\u0436\u043d\u043e \u0441 .NET 7 (\u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Preview 1) \u0438 C# 11.<\/p>\n<\/li>\n<li>\n<p>Rider \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 C# 11 \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 2022.1 EAP \u2014 \u043a\u043e\u0434 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043a \u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 Go to definition, \u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u00a0Visual Studio 17.2 Preview 1 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 .NET 7 \u0438 C# 11.<\/p>\n<\/li>\n<\/ul>\n<h2>\u041b\u043e\u0436\u043a\u0430 \u0434\u0451\u0433\u0442\u044f \u2014 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/h2>\n<p>\u041f\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e regex source generator <a href=\"https:\/\/www.meziantou.net\/regex-source-generator.htm\" rel=\"noopener noreferrer nofollow\">\u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u2014 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 self-contained application, \u043d\u043e \u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0434\u0435\u0431\u0430\u0433\u0430 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code class=\"cs\">[RegexGenerator(@\"(\\+7|7|8)?[\\s\\-]?\\(?[489][0-9]{2}\\)?[\\s\\-]?[0-9]{3}[\\s\\-]?[0-9]{2}[\\s\\-]?[0-9]{2}\"] private partial Regex RussianPhoneNumberRegex();  public string? FindPhoneNumber(string text) {     var match = RussianPhoneNumberRegex().Match(text);     return match.Success ? match.Value : null; }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>362 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">\/\/ &lt;auto-generated\/> #nullable enable #pragma warning disable CS0162 \/\/ Unreachable code #pragma warning disable CS0164 \/\/ Unreferenced label #pragma warning disable CS0219 \/\/ Variable assigned but never used  namespace RegexGeneratorExample {     partial class RegexContainer     {         [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Text.RegularExpressions.Generator\", \"7.0.6.17504\")]         private partial global::System.Text.RegularExpressions.Regex RussianPhoneNumberRegex() => global::System.Text.RegularExpressions.Generated.__2b701bf8.RussianPhoneNumberRegex_0.Instance;     } }  namespace System.Text.RegularExpressions.Generated {     using System;     using System.CodeDom.Compiler;     using System.Collections;     using System.ComponentModel;     using System.Globalization;     using System.Runtime.CompilerServices;     using System.Text.RegularExpressions;     using System.Threading;      [GeneratedCodeAttribute(\"System.Text.RegularExpressions.Generator\", \"7.0.6.17504\")]     [EditorBrowsable(EditorBrowsableState.Never)]     internal static class __2b701bf8     {         \/\/\/ &lt;summary>Custom &lt;see cref=\"Regex\"\/>-derived type for the RussianPhoneNumberRegex method.&lt;\/summary>         internal sealed class RussianPhoneNumberRegex_0 : Regex         {             \/\/\/ &lt;summary>Cached, thread-safe singleton instance.&lt;\/summary>             internal static readonly RussianPhoneNumberRegex_0 Instance = new();                      \/\/\/ &lt;summary>Initializes the instance.&lt;\/summary>             private RussianPhoneNumberRegex_0()             {                 base.pattern = \"(\\\\+7|7|8)?[\\\\s\\\\-]?\\\\(?[489][0-9]{2}\\\\)?[\\\\s\\\\-]?[0-9]{3}[\\\\s\\\\-]?[0-9]{2}[\\\\s\\\\-]?[0-9]{2}\";                 base.roptions = RegexOptions.CultureInvariant;                 base.internalMatchTimeout = TimeSpan.FromMilliseconds(1000);                 base.factory = new RunnerFactory();                 base.capsize = 2;             }                      \/\/\/ &lt;summary>Provides a factory for creating &lt;see cref=\"RegexRunner\"\/> instances to be used by methods on &lt;see cref=\"Regex\"\/>.&lt;\/summary>             private sealed class RunnerFactory : RegexRunnerFactory             {                 \/\/\/ &lt;summary>Creates an instance of a &lt;see cref=\"RegexRunner\"\/> used by methods on &lt;see cref=\"Regex\"\/>.&lt;\/summary>                 protected override RegexRunner CreateInstance() => new Runner();                              \/\/\/ &lt;summary>Provides the runner that contains the custom logic implementing the specified regular expression.&lt;\/summary>                 private sealed class Runner : RegexRunner                 {                     \/\/ Description:                     \/\/ \u25cb Optional (greedy).                     \/\/     \u25cb 1st capture group.                     \/\/         \u25cb Match with 2 alternative expressions.                     \/\/             \u25cb Match the string \"+7\".                     \/\/             \u25cb Match a character in the set [78].                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '(' atomically, optionally.                     \/\/ \u25cb Match a character in the set [489].                     \/\/ \u25cb Match '0' through '9' exactly 2 times.                     \/\/ \u25cb Match ')' atomically, optionally.                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '0' through '9' exactly 3 times.                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '0' through '9' exactly 2 times.                     \/\/ \u25cb Match a character in the set [-\\s] atomically, optionally.                     \/\/ \u25cb Match '0' through '9' exactly 2 times.                                  \/\/\/ &lt;summary>Scan the &lt;paramref name=\"inputSpan\"\/> starting from base.runtextstart for the next match.&lt;\/summary>                     \/\/\/ &lt;param name=\"inputSpan\">The text being scanned by the regular expression.&lt;\/param>                     protected override void Scan(ReadOnlySpan&lt;char> inputSpan)                     {                         \/\/ Search until we can't find a valid starting position, we find a match, or we reach the end of the input.                         while (TryFindNextPossibleStartingPosition(inputSpan))                         {                             base.CheckTimeout();                             if (TryMatchAtCurrentPosition(inputSpan) || base.runtextpos == inputSpan.Length)                             {                                 return;                    <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-331955","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=331955"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331955\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}