Skip to content

Commit 02c1c72

Browse files
committed
fix bug with FileScopedNamespace
1 parent 6a2cb10 commit 02c1c72

File tree

10 files changed

+38
-21
lines changed

10 files changed

+38
-21
lines changed

src/EntityFrameworkCore.Generator.Core/Options/ClassOptionsBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ComponentModel;
23

34
namespace EntityFrameworkCore.Generator.Options;
@@ -57,6 +58,6 @@ public string Directory
5758
/// <value>
5859
/// <c>true</c> to use file-coped namespace; otherwise, <c>false</c>.
5960
/// </value>
60-
[DefaultValue(false)]
61-
public bool FileScopedNamespace { get; set; }
62-
}
61+
[Obsolete("Use ProjectOptions.FileScopedNamespace instead")]
62+
public bool? FileScopedNamespace { get; set; }
63+
}

src/EntityFrameworkCore.Generator.Core/Options/ProjectOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.ComponentModel;
2+
13
namespace EntityFrameworkCore.Generator.Options;
24

35
/// <summary>
@@ -48,6 +50,15 @@ public string Directory
4850
/// <value>
4951
/// If the output should support nullable reference types.
5052
/// </value>
53+
[DefaultValue(false)]
5154
public bool Nullable { get; set; }
5255

53-
}
56+
/// <summary>
57+
/// Gets or sets a value indicating whether to use file-scoped namespace.
58+
/// </summary>
59+
/// <value>
60+
/// <c>true</c> to use file-coped namespace; otherwise, <c>false</c>.
61+
/// </value>
62+
[DefaultValue(false)]
63+
public bool FileScopedNamespace { get; set; }
64+
}

src/EntityFrameworkCore.Generator.Core/Templates/CodeTemplateBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ protected virtual void MergeOutput(string fullPath, string outputContent)
7878

7979
File.WriteAllText(fullPath, finalContent);
8080
}
81-
}
81+
}

src/EntityFrameworkCore.Generator.Core/Templates/DataContextTemplate.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
23
using EntityFrameworkCore.Generator.Extensions;
34
using EntityFrameworkCore.Generator.Metadata.Generation;
45
using EntityFrameworkCore.Generator.Options;
@@ -25,7 +26,7 @@ public override string WriteCode()
2526

2627
CodeBuilder.Append($"namespace {_entityContext.ContextNamespace}");
2728

28-
if (Options.Data.Context.FileScopedNamespace)
29+
if (Options.Project.FileScopedNamespace)
2930
{
3031
CodeBuilder.AppendLine(";");
3132
GenerateClass();
@@ -154,4 +155,4 @@ private void GenerateOnConfiguring()
154155

155156
CodeBuilder.AppendLine("}");
156157
}
157-
}
158+
}

src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
23
using EntityFrameworkCore.Generator.Extensions;
34
using EntityFrameworkCore.Generator.Metadata.Generation;
45
using EntityFrameworkCore.Generator.Options;
@@ -24,7 +25,7 @@ public override string WriteCode()
2425

2526
CodeBuilder.Append($"namespace {_entity.EntityNamespace}");
2627

27-
if (Options.Data.Context.FileScopedNamespace)
28+
if (Options.Project.FileScopedNamespace)
2829
{
2930
CodeBuilder.AppendLine(";");
3031
GenerateClass();
@@ -207,4 +208,4 @@ private void GenerateRelationshipProperties()
207208
CodeBuilder.AppendLine("#endregion");
208209
CodeBuilder.AppendLine();
209210
}
210-
}
211+
}

src/EntityFrameworkCore.Generator.Core/Templates/MapperClassTemplate.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
23
using EntityFrameworkCore.Generator.Extensions;
34
using EntityFrameworkCore.Generator.Metadata.Generation;
45
using EntityFrameworkCore.Generator.Options;
@@ -35,7 +36,7 @@ public override string WriteCode()
3536

3637
CodeBuilder.Append($"namespace {_entity.MapperNamespace}");
3738

38-
if (Options.Data.Context.FileScopedNamespace)
39+
if (Options.Project.FileScopedNamespace)
3940
{
4041
CodeBuilder.AppendLine(";");
4142
GenerateClass();
@@ -141,4 +142,4 @@ private void GenerateConstructor()
141142
CodeBuilder.AppendLine();
142143
}
143144

144-
}
145+
}

src/EntityFrameworkCore.Generator.Core/Templates/MappingClassTemplate.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
using System.Globalization;
22
using System.Linq;
3+
34
using EntityFrameworkCore.Generator.Extensions;
45
using EntityFrameworkCore.Generator.Metadata.Generation;
56
using EntityFrameworkCore.Generator.Options;
7+
68
using Microsoft.EntityFrameworkCore;
79
using Microsoft.EntityFrameworkCore.Metadata;
810

911
namespace EntityFrameworkCore.Generator.Templates;
1012

1113
public class MappingClassTemplate : CodeTemplateBase
1214
{
13-
private Entity _entity;
15+
private readonly Entity _entity;
1416

1517
public MappingClassTemplate(Entity entity, GeneratorOptions options) : base(options)
1618
{
@@ -29,7 +31,7 @@ public override string WriteCode()
2931

3032
CodeBuilder.Append($"namespace {_entity.MappingNamespace}");
3133

32-
if (Options.Data.Context.FileScopedNamespace)
34+
if (Options.Project.FileScopedNamespace)
3335
{
3436
CodeBuilder.AppendLine(";");
3537
GenerateClass();
@@ -104,7 +106,7 @@ private void GenerateConstants()
104106

105107
CodeBuilder.AppendLine($"public const string Name = \"{_entity.TableName}\";");
106108
}
107-
109+
108110
CodeBuilder.AppendLine("}");
109111

110112
CodeBuilder.AppendLine();
@@ -362,4 +364,4 @@ private void GenerateTableMapping()
362364

363365
CodeBuilder.AppendLine();
364366
}
365-
}
367+
}

src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override string WriteCode()
2323

2424
CodeBuilder.Append($"namespace {_model.ModelNamespace}");
2525

26-
if (Options.Data.Context.FileScopedNamespace)
26+
if (Options.Project.FileScopedNamespace)
2727
{
2828
CodeBuilder.AppendLine(";");
2929
GenerateClass();
@@ -119,4 +119,4 @@ private bool ShouldDocument()
119119

120120
return Options.Model.Read.Document;
121121
}
122-
}
122+
}

src/EntityFrameworkCore.Generator.Core/Templates/QueryExtensionTemplate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override string WriteCode()
3030

3131
CodeBuilder.Append($"namespace {extensionNamespace}");
3232

33-
if (Options.Data.Context.FileScopedNamespace)
33+
if (Options.Project.FileScopedNamespace)
3434
{
3535
CodeBuilder.AppendLine(";");
3636
GenerateClass();
@@ -325,4 +325,4 @@ private void AppendLamba(Method method)
325325
if (indented)
326326
CodeBuilder.DecrementIndent();
327327
}
328-
}
328+
}

src/EntityFrameworkCore.Generator.Core/Templates/ValidatorClassTemplate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override string WriteCode()
2727

2828
CodeBuilder.Append($"namespace {_model.ValidatorNamespace}");
2929

30-
if (Options.Data.Context.FileScopedNamespace)
30+
if (Options.Project.FileScopedNamespace)
3131
{
3232
CodeBuilder.AppendLine(";");
3333
GenerateClass();
@@ -116,4 +116,4 @@ private void GenerateConstructor()
116116
CodeBuilder.AppendLine();
117117
}
118118

119-
}
119+
}

0 commit comments

Comments
 (0)