回复 13# 小白龙
手把手包教包会- <#
- .SYNOPSIS
- Get the C# Method body string
-
- .DESCRIPTION
- Get the C# Method body string
-
- .PARAMETER Code
- C# code
-
- .PARAMETER Method
- The method name
-
- .PARAMETER Qualifiers
- the qualifiers of the method,i.e. public,static
-
- .EXAMPLE
- Get-CSBody -Code $s -Method _Main0 -Qualifiers static,public
- Get-CSBody -Code $s -Method _Main2 -Qualifiers static,public,string
-
- .NOTES
- General notes
- #>
- function Get-CSBody {
- param(
- [string]$Code,
- [string]$Method,
- [string[]]$Qualifiers
- )
- $re = [regex]@"
- \b${Method}$(-join ($Qualifiers|ForEach-Object{"(?<=\b${_}\b.*)"}))(?s)(?>\s*)\((?>[^)]*)\)(?>[^{]*)(?<o>\{)(?<body>(?>/\*.*?\*/|//[^\n]*|"(?>""|\\"|[^"])*"|(?<o>\{)|(?<-o>\})|.)*?)(?<-o>\})(?(o)!)
- "@
- $ms = $re.Matches($Code)
- foreach ($m in $ms) {
- #'---------------'|Write-Host -ForegroundColor Green
- $m.Groups['body'].Value
- #'---------------'|Write-Host -ForegroundColor Green
- }
- }
- Get-CSBody -Code $s -Method _Main0 -Qualifiers static,public
- Get-CSBody -Code $s -Method _Main2 -Qualifiers public,string
复制代码
|