Skip to content

Commit 44786fc

Browse files
committed
Fixed a bug caused by generating from a class that is out of the namespace declaration
1 parent ebbe830 commit 44786fc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

AutoEntityGenerator.CodeGenerator/MappingsClassGenerator.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IMappingsClassGenerator
1010

1111
internal class MappingsClassGenerator : CodeGenerator, IMappingsClassGenerator
1212
{
13-
public string GenerateMappingClassCode(Entity from, Entity to)
13+
public string GenerateMappingClassCode(Entity from, Entity to)
1414
{
1515
var properties = GenerateMappingProperties(from);
1616

@@ -39,15 +39,19 @@ private string GenerateCode(Entity from, Entity to, string properties)
3939
var typeParameters = GenerateTypeParameters(to);
4040
var genericConstraints = GenerateGenericConstraints(to);
4141

42+
var toFullName = string.IsNullOrEmpty(to.Namespace.Name)
43+
? to.Name
44+
: to.Namespace.Name + "." + to.Name;
45+
4246
return from.Namespace.IsFileScoped
4347
?
4448
$@"{Comments}namespace {from.Namespace.Name};
4549
4650
public static partial class {from.Name}MappingExtensions
4751
{{
48-
public static {to.Namespace.Name}.{to.Name}{typeParameters} To{to.Name}{typeParameters}(this {from.Name}{typeParameters} source){genericConstraints}
52+
public static {toFullName}{typeParameters} To{to.Name}{typeParameters}(this {from.Name}{typeParameters} source){genericConstraints}
4953
{{
50-
return new {to.Namespace.Name}.{to.Name}{typeParameters}
54+
return new {toFullName}{typeParameters}
5155
{{
5256
{properties}
5357
}};
@@ -58,9 +62,9 @@ public static partial class {from.Name}MappingExtensions
5862
{{
5963
public static partial class {from.Name}MappingExtension
6064
{{
61-
public static {to.Namespace.Name}.{to.Name}{typeParameters} To{to.Name}{typeParameters}(this {from.Name}{typeParameters} source){genericConstraints}
65+
public static {toFullName}{typeParameters} To{to.Name}{typeParameters}(this {from.Name}{typeParameters} source){genericConstraints}
6266
{{
63-
return new {to.Namespace.Name}.{to.Name}{typeParameters}
67+
return new {toFullName}{typeParameters}
6468
{{
6569
{properties}
6670
}};

0 commit comments

Comments
 (0)