@@ -203,6 +203,12 @@ public WrapperValueObjectAttribute(string name1, Type type1, string name2, Type
203
203
"System.Decimal" ,
204
204
} ;
205
205
206
+ private static readonly string [ ] ByteTypes = new [ ]
207
+ {
208
+ "System.SByte" ,
209
+ "System.Byte" ,
210
+ } ;
211
+
206
212
private bool GenerateWrapper ( in GenerationContext context )
207
213
{
208
214
var isReadOnly = context . Node . Modifiers . Any ( m => m . IsKind ( SyntaxKind . ReadOnlyKeyword ) ) ;
@@ -319,6 +325,8 @@ namespace {context.Type.ContainingNamespace}
319
325
320
326
if ( isMathType )
321
327
{
328
+ var isByteType = ByteTypes . Contains ( innerType ) ;
329
+
322
330
// sourceBuilder.AppendLine(@$"
323
331
//");
324
332
context . SourceBuilder . AppendLine ( @$ "
@@ -332,17 +340,6 @@ namespace {context.Type.ContainingNamespace}
332
340
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
333
341
=> _value.TryFormat(destination, out charsWritten, format, provider);
334
342
335
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
336
- public static { context . Type . Name } operator +({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value + right._value);
337
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
338
- public static { context . Type . Name } operator -({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value - right._value);
339
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
340
- public static { context . Type . Name } operator /({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value / right._value);
341
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
342
- public static { context . Type . Name } operator *({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value * right._value);
343
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
344
- public static { context . Type . Name } operator %({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value % right._value);
345
-
346
343
[MethodImpl(MethodImplOptions.AggressiveInlining)]
347
344
public static bool operator <({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value < right._value;
348
345
@@ -355,6 +352,37 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
355
352
[MethodImpl(MethodImplOptions.AggressiveInlining)]
356
353
public static bool operator >=({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value >= right._value;
357
354
" ) ;
355
+ if ( isByteType )
356
+ {
357
+ context . SourceBuilder . AppendLine ( @$ "
358
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
359
+ public static int operator +({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value + right._value;
360
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
361
+ public static int operator -({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value - right._value;
362
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
363
+ public static int operator /({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value / right._value;
364
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
365
+ public static int operator *({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value * right._value;
366
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
367
+ public static int operator %({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value % right._value;
368
+ " ) ;
369
+ }
370
+ else
371
+ {
372
+ context . SourceBuilder . AppendLine ( @$ "
373
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
374
+ public static { context . Type . Name } operator +({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value + right._value);
375
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
376
+ public static { context . Type . Name } operator -({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value - right._value);
377
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
378
+ public static { context . Type . Name } operator /({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value / right._value);
379
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
380
+ public static { context . Type . Name } operator *({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value * right._value);
381
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
382
+ public static { context . Type . Name } operator %({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => new { context . Type . Name } (left._value % right._value);
383
+ " ) ;
384
+ }
385
+
358
386
}
359
387
else
360
388
{
0 commit comments