-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_namespaces.ps1
More file actions
37 lines (27 loc) · 1.12 KB
/
Copy pathadd_namespaces.ps1
File metadata and controls
37 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# === CONFIGURATION ===
# Change this to match your base/root namespace
$baseNamespace = "AlfaEBetto"
# Path to the root of your C# project
$root = "D:\git\alfaebeto\alfaebeto"
# ======================
$root = [System.IO.Path]::GetFullPath($root)
Get-ChildItem -Path $root -Recurse -Filter *.cs | Where-Object {
($_ | Select-String -Pattern '\bclass\b') -and
-not ($_ | Select-String -Pattern '^\s*namespace\b')
} | ForEach-Object {
$file = $_.FullName
$relativePath = $file.Substring($root.Length).TrimStart('\') -replace '\\', '/'
$folderPath = (Split-Path $relativePath -Parent) -replace '/', '.'
$namespace = if ($folderPath -eq '') { $baseNamespace } else { "$baseNamespace.$folderPath" }
Write-Host "Fixing: $file → namespace $namespace"
$originalLines = Get-Content $file
$indentedLines = $originalLines | ForEach-Object { " $_" }
$newContent = @()
$newContent += "namespace $namespace"
$newContent += "{"
$newContent += $indentedLines
$newContent += "}"
# Optional backup
Copy-Item $file "$file.bak"
Set-Content -Path $file -Value $newContent -Encoding UTF8
}