{"id":172917,"date":"2020-10-26T00:22:11","date_gmt":"2020-10-25T16:22:11","guid":{"rendered":"http:\/\/4563.org\/?p=172917"},"modified":"2020-10-26T00:22:11","modified_gmt":"2020-10-25T16:22:11","slug":"%e6%b1%82%e6%95%99-c%e7%b1%bb%e7%9a%84%e5%88%9d%e5%a7%8b%e5%8c%96%e5%8f%98%e9%87%8f%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=172917","title":{"rendered":"\u6c42\u6559 C#\u7c7b\u7684\u521d\u59cb\u5316\u53d8\u91cf\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u6559 C#\u7c7b\u7684\u521d\u59cb\u5316\u53d8\u91cf\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : crella <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u5916\u90e8\u4ee3\u7801\u600e\u4e48\u7528 Ngan.re_dict \u6765\u8bbf\u95ee Ngan \u7c7b\u7684 Dictionary&lt;string, Regex&gt; redict \uff08\u4e5f\u9700\u8981\u8fd9\u6837\u6765\u8bbf\u95ee Ngan.re_funcs)\uff0c\u521d\u8877\u662f\u5728\u67d0\u4e9b\u6d41\u7a0b\u91cc\u51cf\u5c11\u91cd\u590d\u751f\u6210\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6700\u597d\u8fd8\u662f\u7528 Dictionary \u65b9\u5f0f\u6765\u50a8\u5b58\uff08\u5176\u4ed6\u7684\u4e0d\u4f1a&#8230;)<\/p>\n<pre><code>public class Ngan  {    public static Dictionary&lt;Regex, Func&lt;string, string&gt;&gt; re_funcs;   public static Dictionary&lt;string, Regex&gt; re_dict;   public Ngan()   {      \/\/ \u8bfb\u53d6\u6b63\u5219\u8868\u8fbe\u5f0f\u5230\u7f13\u5b58    load_re_dict();    load_re_funcs();   }      private static void load_re_dict(){    re_dict = new Dictionary&lt;string, Regex&gt;();    Regex quote_re = new Regex(@\"[quote](.*?)[\/quote]\", RegexOptions.Multiline);    Regex uid_re = new Regex(@\"[uid.*?](.*?)[\/uid]\");    Regex quoted_re = new Regex(@\"[\/b](.*?)[\/quote]\", RegexOptions.Multiline);    Regex collapse_re = new Regex(@\"[collapse(=.*?)](.*?)[\/collapse]\", RegexOptions.Multiline);        re_dict[\"quote\"] = quote_re;    re_dict[\"uid\"] = uid_re;    re_dict[\"quoted\"] = quoted_re;    re_dict[\"collapse\"] = collapse_re;   }      private static void load_re_funcs(){        re_funcs = new Dictionary&lt;Regex, Func&lt;string, string&gt;&gt;();    \/\/ \u5904\u7406\u56de\u590d\u5185\u5bb9     Regex reply_re = new Regex(@\"Replysto.*?[uid.*?](.*?)[\/uid].*?[\/b]\", RegexOptions.Multiline);    Func&lt;string, string&gt; reply_act = (con) =&gt; String.Format( \"&lt;br&gt;&lt;i&gt;&lt;b&gt;\u56de\u590d&lt;\/b&gt;{0}&lt;\/i&gt;&lt;br&gt;\", con);    re_funcs.Add(reply_re, reply_act);        \/\/ \u94fe\u63a5    Regex link_re = new Regex(@\"[url](.*?)[\/url]\");    Func&lt;string, string&gt; link_act = (con) =&gt; {     if (!con.StartsWith(\"http\")){      con = \"http:\/\/\" + con; \/\/ \u81ea\u52a8\u6dfb\u52a0 http:\/\/\u524d\u7f00     }     return (\"&lt;a href=\"\" + con + \"\" target=\"_blank\"&gt;\u94fe\u63a5&lt;\/a&gt;\");    };    re_funcs.Add(link_re, link_act);       } \/\/ ...  } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3886656\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : geelaw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u9759\u6001\u6784\u9020\u5668\uff0c\u5177\u4f53\u6765\u8bf4\u628a public Ngan \u6539\u6210 static Ngan \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3886657\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : WeaPoon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8c8c\u4f3c\u6ca1\u660e\u767d\u4f60\u60f3\u95ee\u7684\uff0c\u4f60\u662f\u60f3\u95ee\uff0c\u4e0d\u8981\u603b\u662f\u521d\u59cb\u5316 load \u4e48\uff1f<br \/>\u5982\u679c\u662f\u8fd9\u610f\u601d\uff0c\u53ef\u4ee5\u7528 public static Ngan(){} \u53ea\u4f1a\u521d\u59cb\u5316\u4e00\u6b21\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3886658\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : WeaPoon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1 \u8bf4\u7684\u5bf9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3886659\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lukaz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u95ee\u9898\u95ee\u7684\u4e0d\u662f\u5f88\u6e05\u695a\uff0c\u4f46\u6211\u731c\u4f60\u9700\u8981\u7684\u662f\u628a\u6784\u9020\u65b9\u6cd5\u53d8\u6210 static \u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u6559 C#\u7c7b\u7684\u521d\u59cb\u5316\u53d8\u91cf\u95ee\u9898 \u8cc7\u6df1&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172917"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172917"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172917\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172917"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}