-
-
Save auliere/5f1c8feeb4717bbea69d1863ac3b444f to your computer and use it in GitHub Desktop.
Script to break up files by namespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string] $FileName | |
) | |
$GeneratedFileHeader = "//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
" | |
$lines = [System.IO.File]::ReadAllLines((Join-Path -Path $PSScriptRoot -ChildPath $FileName)) | |
foreach($line in $lines) { | |
switch -regex -casesensitive ($line) { | |
'^namespace (.*) \{' { | |
if ($OutputFileStream -ne $null) { | |
$OutputFileStream.Close() | |
} | |
$NewFile = $Matches[1] + '.cs' | |
$OutputFileStream = New-Object io.streamwriter (Join-Path -Path $PSScriptRoot -ChildPath $NewFile) | |
$OutputFileStream.WriteLine($GeneratedFileHeader) | |
$OutputFileStream.WriteLine($_) | |
} | |
default { | |
if ($OutputFileStream -ne $null) { | |
$OutputFileStream.WriteLine($_) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment