@@ -69,13 +69,40 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
69
69
MemberType . Field => data . Name ,
70
70
MemberType . Property => data . Name ,
71
71
MemberType . Method => $ "{ data . Name } ()",
72
- _ => "Unknown member type "
72
+ _ => "ScrollUpInLogForActualError_WPILIB1001 "
73
73
} ;
74
74
75
75
var path = string . IsNullOrWhiteSpace ( data . AttributeInfo . Path ) ? data . Name : data . AttributeInfo . Path ;
76
76
77
77
if ( data . MemberDeclaration . LoggedType == DeclarationType . Logged )
78
78
{
79
+ // If we're a basic logged, just do a simple ? based null check if possible.
80
+ if ( data . MemberDeclaration . LoggedKind == DeclarationKind . None || data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType || data . MemberDeclaration . LoggedKind == DeclarationKind . NullableReferenceType )
81
+ {
82
+ builder . Append ( getOperation ) ;
83
+ if ( data . MemberDeclaration . LoggedKind != DeclarationKind . None )
84
+ {
85
+ builder . Append ( "?" ) ;
86
+ }
87
+ builder . Append ( ".UpdateStereologue($\" {path}/" ) ;
88
+ builder . Append ( path ) ;
89
+ builder . Append ( "\" , logger);" ) ;
90
+ }
91
+ else
92
+ {
93
+ // We're an array, loop
94
+ builder . AppendLine ( $ "foreach(var __tmpValue in { getOperation } )") ;
95
+ builder . AppendLine ( " {" ) ;
96
+ builder . Append ( " __tmpValue" ) ;
97
+ if ( data . MemberDeclaration . SpecialType == SpecialType . System_Nullable_T )
98
+ {
99
+ builder . Append ( "?" ) ;
100
+ }
101
+ builder . Append ( ".UpdateStereologue($\" {path}/" ) ;
102
+ builder . Append ( path ) ;
103
+ builder . AppendLine ( "\" , logger);" ) ;
104
+ builder . AppendLine ( " }" ) ;
105
+ }
79
106
return ;
80
107
}
81
108
@@ -92,39 +119,23 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
92
119
{
93
120
logMethod = "LogStruct" ;
94
121
}
95
- if ( data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType )
96
- {
97
- getOperation = $ "{ getOperation } .GetValueOrDefault()";
98
- }
99
122
}
100
123
101
124
else if ( data . MemberDeclaration . LoggedType == DeclarationType . Protobuf )
102
125
{
103
126
104
127
if ( data . MemberDeclaration . LoggedKind != DeclarationKind . None && data . MemberDeclaration . LoggedKind != DeclarationKind . NullableValueType && data . MemberDeclaration . LoggedKind != DeclarationKind . NullableReferenceType )
105
128
{
106
- logMethod = "Cannot log an array of protobufs " ;
129
+ logMethod = "ScrollUpInLogForActualError_WPILIB1004 " ;
107
130
}
108
131
else
109
132
{
110
133
logMethod = "LogProto" ;
111
134
}
112
- if ( data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType )
113
- {
114
- getOperation = $ "{ getOperation } .GetValueOrDefault()";
115
- }
116
135
}
117
136
else if ( data . MemberDeclaration . LoggedKind == DeclarationKind . None || data . MemberDeclaration . LoggedKind == DeclarationKind . NullableReferenceType || data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType )
118
137
{
119
138
// We're not an array. We're either Nullable<T> or a plain type
120
- if ( data . MemberDeclaration . SpecialType == SpecialType . System_String )
121
- {
122
- getOperation = $ "{ getOperation } .AsSpan()";
123
- }
124
- else if ( data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType )
125
- {
126
- getOperation = $ "{ getOperation } .GetValueOrDefault()";
127
- }
128
139
if ( data . MemberDeclaration . SpecialType == SpecialType . System_UInt64 || data . MemberDeclaration . SpecialType == SpecialType . System_IntPtr || data . MemberDeclaration . SpecialType == SpecialType . System_UIntPtr )
129
140
{
130
141
getOperation = $ "(long){ getOperation } ";
@@ -147,16 +158,12 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
147
158
SpecialType . System_UInt64 => "LogInteger" ,
148
159
SpecialType . System_IntPtr => "LogInteger" ,
149
160
SpecialType . System_UIntPtr => "LogInteger" ,
150
- _ => $ "Unknown Type: { data . MemberDeclaration } "
161
+ _ => $ "ScrollUpInLogForActualError_WPILIB1002 "
151
162
} ;
152
163
}
153
164
else
154
165
{
155
166
// We're array of a basic type
156
- if ( data . MemberDeclaration . LoggedKind != DeclarationKind . ReadOnlySpan && data . MemberDeclaration . LoggedKind != DeclarationKind . Span )
157
- {
158
- getOperation = $ "{ getOperation } .AsSpan()";
159
- }
160
167
161
168
logMethod = data . MemberDeclaration . SpecialType switch
162
169
{
@@ -166,10 +173,32 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
166
173
SpecialType . System_Double => "LogDoubleArray" ,
167
174
SpecialType . System_Byte => "LogRaw" ,
168
175
SpecialType . System_Int64 => "LogIntegerArray" ,
169
- _ => $ "Unknown Array: { data . MemberDeclaration } "
176
+ _ => $ "ScrollUpInLogForActualError_WPILIB1003 "
170
177
} ;
171
178
}
172
179
180
+ bool isNullable = false ;
181
+
182
+ if ( data . MemberDeclaration . LoggedKind == DeclarationKind . Array || data . MemberDeclaration . LoggedKind == DeclarationKind . NullableReferenceType || data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType )
183
+ {
184
+ // We're nullable. We need to do some tricks.
185
+ builder . AppendLine ( "{" ) ;
186
+ builder . AppendLine ( $ " var __tmpValue = { getOperation } ;") ;
187
+ builder . AppendLine ( $ " if (__tmpValue is not null)") ;
188
+ builder . AppendLine ( " {" ) ;
189
+ builder . Append ( " " ) ;
190
+ getOperation = "__tmpValue" ;
191
+ if ( data . MemberDeclaration . SpecialType == SpecialType . System_String || data . MemberDeclaration . LoggedKind == DeclarationKind . Array )
192
+ {
193
+ getOperation = $ "{ getOperation } .AsSpan()";
194
+ }
195
+ if ( data . MemberDeclaration . LoggedKind == DeclarationKind . NullableValueType )
196
+ {
197
+ getOperation = $ "{ getOperation } .Value";
198
+ }
199
+ isNullable = true ;
200
+ }
201
+
173
202
builder . Append ( "logger." ) ;
174
203
builder . Append ( logMethod ) ;
175
204
builder . Append ( "($\" {path}/" ) ;
@@ -181,6 +210,13 @@ private static void ConstructCall(LoggableMember data, StringBuilder builder, So
181
210
builder . Append ( ", " ) ;
182
211
builder . Append ( data . AttributeInfo . LogLevel ) ;
183
212
builder . Append ( ");" ) ;
213
+
214
+ if ( isNullable )
215
+ {
216
+ builder . AppendLine ( ) ;
217
+ builder . AppendLine ( " }" ) ;
218
+ builder . Append ( " }" ) ;
219
+ }
184
220
}
185
221
186
222
public static void AddClassDeclaration ( LoggableType type , StringBuilder builder )
0 commit comments