@@ -203,6 +203,12 @@ public WrapperValueObjectAttribute(string name1, Type type1, string name2, Type
203203 "System.Decimal" ,
204204 } ;
205205
206+ private static readonly string [ ] ByteTypes = new [ ]
207+ {
208+ "System.SByte" ,
209+ "System.Byte" ,
210+ } ;
211+
206212 private bool GenerateWrapper ( in GenerationContext context )
207213 {
208214 var isReadOnly = context . Node . Modifiers . Any ( m => m . IsKind ( SyntaxKind . ReadOnlyKeyword ) ) ;
@@ -319,6 +325,8 @@ namespace {context.Type.ContainingNamespace}
319325
320326 if ( isMathType )
321327 {
328+ var isByteType = ByteTypes . Contains ( innerType ) ;
329+
322330 // sourceBuilder.AppendLine(@$"
323331 //");
324332 context . SourceBuilder . AppendLine ( @$ "
@@ -332,17 +340,6 @@ namespace {context.Type.ContainingNamespace}
332340 public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
333341 => _value.TryFormat(destination, out charsWritten, format, provider);
334342
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-
346343 [MethodImpl(MethodImplOptions.AggressiveInlining)]
347344 public static bool operator <({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value < right._value;
348345
@@ -355,6 +352,37 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
355352 [MethodImpl(MethodImplOptions.AggressiveInlining)]
356353 public static bool operator >=({ ( isReadOnly ? "in " : "" ) } { context . Type . Name } left, { ( isReadOnly ? "in " : "" ) } { context . Type . Name } right) => left._value >= right._value;
357354" ) ;
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+
358386 }
359387 else
360388 {
0 commit comments