Skip to content

Instantly share code, notes, and snippets.

@stevencohn
Created December 25, 2021 14:49
Show Gist options
  • Save stevencohn/9b059a0b701eda193da7c104abd7f8f7 to your computer and use it in GitHub Desktop.
Save stevencohn/9b059a0b701eda193da7c104abd7f8f7 to your computer and use it in GitHub Desktop.
Remove all #region and #endregion lines from all *.cs files under a root folder
void Main()
{
// remove all occurances of #region and #endregion from CS files under a root folder
var root = @"C:\Users\steve\Downloads\System_Windows_Forms_Calendar_003";
var files = Directory.EnumerateFiles(root, "*.cs", SearchOption.AllDirectories);
if (files.Any())
{
var regex = new Regex(@"^\s*#(?:end)?region.*$");
foreach (var path in files)
{
path.Dump();
var lines = File.ReadAllLines(path);
File.WriteAllLines(path, lines.Where(l => !regex.Match(l).Success));
}
}
}
@stevencohn
Copy link
Author

This can pasted into LINQPad. Change the root variable to point to the folder containing source code. It will look for all *.cs files under that folder and remove all #region and #endregion lines from every file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment