Skip to content

Commit

Permalink
Generate Parameterless Constructor beside the Parameterized one.
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-hassan committed Mar 17, 2024
1 parent 6aa8ce6 commit 6799ae7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions OData2Poco.Tests/ConstructorGeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void Ctor_generation_full_test()
{
//Arrange
var expected = """
public Customer () { }
public Customer (int categoryID, string description)
{
CategoryID = categoryID;
Expand Down
6 changes: 5 additions & 1 deletion OData2PocoLib/ConstructorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public static string GenerateFullConstructor(
PocoSetting? pocoSetting = null)
{
pocoSetting ??= new PocoSetting();
if (classTemplate is null)
return string.Empty;
if (pocoSetting.WithConstructor == Ctor.None)
return string.Empty;
var className = classTemplate.Name;
Expand All @@ -82,7 +84,9 @@ public static string GenerateFullConstructor(
assignmentList.Add(pg.AssignmentDeclaration);
}

textTemplate.Write("public ")
var parameterLessConstructor = $"public {className} () {{}}\r\n";
textTemplate.WriteLine(parameterLessConstructor)
.Write("public ")
.Write(className)
.WriteLine(GeneratePrimaryConstructor(classTemplate, pocoSetting))
.WriteLine("{")
Expand Down

0 comments on commit 6799ae7

Please sign in to comment.