Skip to content

Instantly share code, notes, and snippets.

@auliere
Created July 11, 2021 22:21
Show Gist options
  • Save auliere/5f1c8feeb4717bbea69d1863ac3b444f to your computer and use it in GitHub Desktop.
Save auliere/5f1c8feeb4717bbea69d1863ac3b444f to your computer and use it in GitHub Desktop.
Script to break up files by namespaces
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