그래서 PowerShell을 사용하여 파일 맨 위에 C# "using"문을 정렬하려고합니다. 지정된 입력 파일 File.cs를 들어, 사용하는 문은 다음과 같이 : PowerShell 정렬 순서가 잘못되었습니다.
using System.Reflection;
using System.Configuration;
using System.Runtime.Caching;
using System.Linq;
using System;
나는 출력이 "사용"처음으로 "시스템을 사용하여"이 기대하지만, 실제로 정렬 - 개체 하단에 정렬합니다. 목록의 맨 위로 정렬하려면 어떻게 변경합니까?
function Update-UsingStatements
{
param (
[Parameter(Mandatory=$true)][string]$FilePath
)
$fileLines = Get-Content $FilePath
$contents = $fileLines | Out-String
$list = New-Object 'System.Collections.Generic.List[string]'
$contents | Select-String -pattern 'using\s[\w\.]+;' -AllMatches | ForEach-Object {$_.Matches} | ForEach-Object { $list.Add($_.Value) }
$list = $list | Sort-Object
for ($i = 0; $i -lt $list.Count; $i++)
{
$fileLines[$i] = $list[$i]
}
$fileLines | Out-File $FilePath -Encoding utf8
}
저는 100k 연례 업적에 대해 아주 늦었지만 gratz입니다. 겸손한 나를 존경 해주세요. 당신의 수정처럼 맑은 답변을 얻을 자격이 있습니다. – sodawillow
나는 같은 생각을 가지고 있었지만'-replace' 대신에'$ _. TrimEnd (';')'를 사용하려고했습니다. 별도의 답변으로 게시 할 낭비로 보였으므로 옵션을 추가하기 위해 귀하의 의견을 추가하고 있습니다. 답변 Ansgar, 강한 직장에 주목! – TheMadTechnician
@sodawillow 감사합니다. –