File tree Expand file tree Collapse file tree
.idea/.idea.Porticle.Grpc/.idea Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11namespace Porticle . Grpc . GuidMapper ;
22
3+ /// <summary>
4+ /// Represents a mapping between a property name and its corresponding field name.
5+ /// </summary>
36public record PropertyToField ( string PropertyName , string FieldName ) ;
Original file line number Diff line number Diff line change @@ -39,10 +39,43 @@ public class PropertyVisitor : CSharpSyntaxRewriter
3939 // dont change anything
4040 return null ;
4141
42- if ( ! property . GetLeadingTrivia ( ) . ToFullString ( ) . Contains ( "[GrpcGuid]" ) )
43- // dont change anything
42+ if ( property . GetLeadingTrivia ( ) . ToFullString ( ) . Contains ( "[GrpcGuid]" ) )
43+ {
44+ return ConcertToGuidProperty ( property ) ;
45+ }
46+
47+ if ( property . GetLeadingTrivia ( ) . ToFullString ( ) . Contains ( "[NullableString]" ) )
48+ {
49+ return ConcertToNullableStringProperty ( property ) ;
50+ }
51+
52+ return null ;
53+ }
54+
55+ private PropertyDeclarationSyntax ? ConcertToNullableStringProperty ( PropertyDeclarationSyntax property )
56+ {
57+ var setter = property . AccessorList ? . Accessors . FirstOrDefault ( a => a . IsKind ( SyntaxKind . SetAccessorDeclaration ) ) ;
58+
59+ if ( setter ? . Body == null )
60+ {
61+ Console . WriteLine ( $ "[Error] No setter found in property { property . Identifier } ") ;
4462 return null ;
63+ }
4564
65+ var isNullable = ! setter . Body . ToFullString ( ) . Contains ( "ProtoPreconditions.CheckNotNull" ) ;
66+
67+ if ( ! isNullable )
68+ {
69+ Console . WriteLine ( $ "[Error] String property { property . Identifier } ist not nullable") ;
70+ return null ;
71+ }
72+
73+ // Change property type to string?
74+ return property . WithType ( SyntaxFactory . ParseTypeName ( "global::System.String?" ) . WithTrailingTrivia ( SyntaxFactory . Space ) ) ;
75+ }
76+
77+ private PropertyDeclarationSyntax ? ConcertToGuidProperty ( PropertyDeclarationSyntax property )
78+ {
4679 var setter = property . AccessorList ? . Accessors . FirstOrDefault ( a => a . IsKind ( SyntaxKind . SetAccessorDeclaration ) ) ;
4780
4881 if ( setter ? . Body == null )
You can’t perform that action at this time.
0 commit comments