Created
October 19, 2019 21:34
-
-
Save Tempest1000/3636ccea01cdfafac8c5a715796e3b54 to your computer and use it in GitHub Desktop.
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
void Main() | |
{ | |
var files = Directory.EnumerateFiles(@"enter-path-to-files-here", "*.cs", SearchOption.TopDirectoryOnly); | |
foreach (var file in files) | |
{ | |
// hardcoding is bad | |
if (file.Contains("Enum.cs")) continue; | |
ParseFile(File.ReadAllLines(file)); | |
} | |
} | |
// Define other methods and classes here | |
void ParseFile(string[] fileLines) | |
{ | |
//Array.ForEach(fileLines, x => x = x.Replace(" { get; set; }", string.Empty)); | |
var list = fileLines.ToList().Select(s => s.Replace(" { get; set; }", string.Empty)).ToList(); | |
list = list.ToList().Select(s => s.Replace("public ", string.Empty)).ToList(); | |
list = list.ToList().Select(s => s.Replace(" : IObjectWithState", string.Empty)).ToList(); | |
var keepList = new List<string>(); | |
foreach (var line in list) | |
{ | |
string[] ignoreStrings = { "///", "//", "using", "namespace", " {", " }", "[Required]", "new", "{", "}", "(", ")", "this.", "return", " ObjectState State", "#region", "#endregion" }; | |
if (ignoreStrings.Any(line.Contains)) continue; | |
keepList.Add(line); | |
} | |
//list = list.ToList().Select(s => s.Replace("class ", string.Empty) + " {").ToList(); | |
foreach (var line in keepList) | |
{ | |
var entityLine = string.Empty; | |
if (line.Contains("class ")) entityLine = "} " + line.Replace("class ", "entity ") + " {"; | |
if (line.Contains(" ")) entityLine = line; | |
if (entityLine.Contains(" string ")) entityLine = entityLine.Replace(" string ", string.Empty) + " String"; | |
if (entityLine.Contains(" DateTime ")) entityLine = entityLine.Replace(" DateTime ", string.Empty) + " DateTime"; | |
if (entityLine.Contains(" int ")) entityLine = entityLine.Replace(" int ", string.Empty) + " Long"; | |
// hardcoding is bad | |
if (entityLine.Contains(" virtual Message Message")) entityLine = entityLine.Replace(" virtual Message Message", "Message Message"); | |
if (entityLine.Contains(" virtual ")) | |
{ | |
var virtualLine = entityLine.Replace(" virtual ", string.Empty); | |
string[] parts = virtualLine.Split(' '); | |
entityLine = parts[1].Trim() + " " + parts[0].Trim(); | |
} | |
entityLine = entityLine.Replace("} ", "}\n\n"); | |
if (entityLine.Trim().Length == 0) continue; | |
//if (counter == 0 && entityLine.Contains("{")) entityLine = entityLine.Replace("}", string.Empty); | |
entityLine.Dump(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment