回复 15# idwma
我测试的这个函数,
DownloadFileAsync
, 一直运行, 停不下来了, 我就改了下面两个红色字的地方
(?<a>\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*)|\s*)*(?<c>DownloadFileAsync\s*\(.*\)\s*\{(?:[^{}]+|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\})', '${a}public static ${b}${c}- $s = @'
- // 返回Nullable类型
- int? GetNullableInt()
- {
- int? result = null;
- return result;
- }
-
- // 返回Tuple类型
- (string, int) GetPersonInfo()
- {
- string name = "张三";
- int age = 20;
- return (name, age);
- }
-
- // 返回IEnumerable类型
- IEnumerable<int> GetNumbers()
- {
- yield return 1;
- yield return 2;
- yield return 3;
- }
-
- // 返回Task类型
- async Task<string> DownloadFileAsync(string url)
- {
- HttpClient client = new HttpClient();
- HttpResponseMessage response = await client.GetAsync(url);
- string content = await response.Content.ReadAsStringAsync();
- return content;
- }
- '@
-
- $s -replace '(?<a>\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*)|\s*)*(?<c>DownloadFileAsync\s*\(.*\)\s*\{(?:[^{}]+|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\})', '${a}public static ${b}${c}'
复制代码
|