Skip to content

Commit

Permalink
Add new advanced option: "No default DbContext constructor"
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ committed Jul 11, 2021
1 parent 1ea6a14 commit b85c77d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/GUI/RevEng.Core/ReverseEngineerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ public static ReverseEngineerResult GenerateFiles(ReverseEngineerCommandOptions
File.WriteAllLines(filePaths.ContextFile, dbContextLines);
}
}
#else
RemoveOnConfiguring(filePaths.ContextFile, options.IncludeConnectionString);
#endif
RemoveFragments(filePaths.ContextFile, options.ContextClassName, options.IncludeConnectionString, options.UseNoDefaultConstructor);
if (!options.UseHandleBars)
{
PostProcess(filePaths.ContextFile);
Expand Down Expand Up @@ -189,15 +188,26 @@ private static List<string> SplitDbContext(string contextFile, bool useDbContext
return DbContextSplitter.Split(contextFile, contextNamespace, supportNullable);
}

private static void RemoveOnConfiguring(string contextFile, bool includeConnectionString)
private static void RemoveFragments(string contextFile, string contextName, bool includeConnectionString, bool removeDefaultConstructor)
{
if (string.IsNullOrEmpty(contextFile))
{
return;
}

var finalLines = new List<string>();
var lines = File.ReadAllLines(contextFile);
var lines = File.ReadAllLines(contextFile).ToList();

if (removeDefaultConstructor)
{
var index = lines.IndexOf($" public {contextName}()");
if (index != -1)
{
lines.RemoveAt(index + 2);
lines.RemoveAt(index + 1);
lines.RemoveAt(index);
}
}

int i = 1;
var inConfiguring = false;
Expand Down Expand Up @@ -227,6 +237,7 @@ private static void RemoveOnConfiguring(string contextFile, bool includeConnecti
finalLines.Add(line);
i++;
}

File.WriteAllLines(contextFile, finalLines, Encoding.UTF8);
}

Expand Down
1 change: 1 addition & 0 deletions src/GUI/efreveng/TestFiles/fulltest.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
"UseInflector": true,
"UseLegacyPluralizer": false,
"UseNoConstructor": false,
"UseNoDefaultConstructor": true,
"UseNoNavigations": false,
"UseNodaTime": true,
"UseNullableReferences": false,
Expand Down
Binary file modified src/GUI/lib/efreveng.exe.zip
Binary file not shown.
Binary file modified src/GUI/lib/efreveng50.exe.zip
Binary file not shown.
Binary file modified src/GUI/lib/efreveng60.exe.zip
Binary file not shown.

0 comments on commit b85c77d

Please sign in to comment.