Skip to content

Commit 05e366e

Browse files
author
machibuse
committed
Add test project for GuidMapper and enhance converters in ClassVisitor and PropertyVisitor
1 parent 2978ae8 commit 05e366e

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Porticle.Grpc.GuidMapper.Tests;
2+
3+
public class Class1
4+
{
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

Source/Porticle.Grpc.GuidMapper/ClassVisitor.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,23 @@ public class ClassVisitor : CSharpSyntaxRewriter
2525
var propertyVisitor = new PropertyVisitor();
2626
node = (ClassDeclarationSyntax)propertyVisitor.Visit(node);
2727

28-
node = node.AddMembers(ClassFromSource(ListWrappers.RepeatedFieldGuidWrapper));
29-
node = node.AddMembers(ClassFromSource(ListWrappers.RepeatedFieldNullableGuidWrapper));
30-
node = node.AddMembers(ClassFromSource(ListWrappers.RepeatedFieldNullableStringWrapper));
28+
if (propertyVisitor.NeedGuidConverter)
29+
{
30+
node = node.AddMembers(ClassFromSource(ListWrappers.RepeatedFieldGuidWrapper));
31+
}
32+
33+
if (propertyVisitor.NeedNullableGuidConverter)
34+
{
35+
node = node.AddMembers(ClassFromSource(ListWrappers.RepeatedFieldNullableGuidWrapper));
36+
}
37+
38+
if (propertyVisitor.NeedNullableStringConverter)
39+
{
40+
node = node.AddMembers(ClassFromSource(ListWrappers.RepeatedFieldNullableStringWrapper));
41+
}
42+
43+
44+
3145

3246
Console.WriteLine("Visit Methods for "+propertyVisitor.ReplaceProps.Count+" props");
3347
var methodVisitor = new MethodVisitor(propertyVisitor.ReplaceProps);

Source/Porticle.Grpc.GuidMapper/PropertyVisitor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class PropertyVisitor : CSharpSyntaxRewriter
7878
{
7979
if (isNullable)
8080
{
81+
NeedNullableGuidConverter = true;
8182
var newReturnExpression = SyntaxFactory.InvocationExpression(
8283
SyntaxFactory.ParseExpression("new RepeatedFieldNullableGuidWrapper"), // Die Methode
8384
SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(originalReturnExpression))));
@@ -89,6 +90,7 @@ public class PropertyVisitor : CSharpSyntaxRewriter
8990
}
9091
else
9192
{
93+
NeedGuidConverter = true;
9294
var newReturnExpression = SyntaxFactory.InvocationExpression(
9395
SyntaxFactory.ParseExpression("new RepeatedFieldGuidWrapper"), // Die Methode
9496
SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(originalReturnExpression))));
@@ -104,6 +106,7 @@ public class PropertyVisitor : CSharpSyntaxRewriter
104106
{
105107
if (isNullable)
106108
{
109+
NeedNullableStringConverter = true;
107110
var newReturnExpression = SyntaxFactory.InvocationExpression(
108111
SyntaxFactory.ParseExpression("new RepeatedFieldNullableStringWrapper"), // Die Methode
109112
SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(originalReturnExpression))));

Source/Porticle.Grpc.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Porticle.Grpc.GuidMapper", "Porticle.Grpc.GuidMapper\Porticle.Grpc.GuidMapper.csproj", "{5EF937F2-BE28-4634-A6D4-C7CACADCF1D7}"
44
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Porticle.Grpc.GuidMapper.Tests", "Porticle.Grpc.GuidMapper.Tests\Porticle.Grpc.GuidMapper.Tests.csproj", "{FC37AFB0-CE1E-473B-B5A3-BFA678C4B770}"
6+
EndProject
57
Global
68
GlobalSection(SolutionConfigurationPlatforms) = preSolution
79
Debug|Any CPU = Debug|Any CPU
@@ -12,5 +14,9 @@ Global
1214
{5EF937F2-BE28-4634-A6D4-C7CACADCF1D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
1315
{5EF937F2-BE28-4634-A6D4-C7CACADCF1D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
1416
{5EF937F2-BE28-4634-A6D4-C7CACADCF1D7}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{FC37AFB0-CE1E-473B-B5A3-BFA678C4B770}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{FC37AFB0-CE1E-473B-B5A3-BFA678C4B770}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{FC37AFB0-CE1E-473B-B5A3-BFA678C4B770}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{FC37AFB0-CE1E-473B-B5A3-BFA678C4B770}.Release|Any CPU.Build.0 = Release|Any CPU
1521
EndGlobalSection
1622
EndGlobal

0 commit comments

Comments
 (0)