@@ -348,14 +348,10 @@ namespace {containingNamespace}
348348 : { Constants . WrapperValueObjectTypeName } <{ underlyingTypeFullyQualifiedName } >,
349349 IEquatable<{ typeName } >,
350350 { ( isComparable ? "" : "/*" ) } IComparable<{ typeName } >,{ ( isComparable ? "" : "*/" ) }
351- #if NET7_0_OR_GREATER
352351 ISpanFormattable,
353352 ISpanParsable<{ typeName } >,
354- #endif
355- #if NET8_0_OR_GREATER
356353 IUtf8SpanFormattable,
357354 IUtf8SpanParsable<{ typeName } >,
358- #endif
359355 { Constants . SerializableDomainObjectInterfaceTypeName } <{ typeName } , { underlyingTypeFullyQualifiedName } >
360356 {{
361357 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . StringComparison ) ? "/*" : "" ) }
@@ -439,30 +435,21 @@ public int CompareTo({typeName}? other)
439435
440436 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . DeserializeFromUnderlying ) ? "/*" : "" ) }
441437 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . UnsettableValue ) ? $@ "
442- #if NET8_0_OR_GREATER
443438 [System.Runtime.CompilerServices.UnsafeAccessor(System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = ""{ valueFieldName } "")]
444- private static extern ref { underlyingTypeFullyQualifiedName } GetValueFieldReference({ typeName } instance);
445- #elif NET7_0_OR_GREATER
446- private static readonly System.Reflection.FieldInfo ValueFieldInfo = typeof({ typeName } ).GetField(""{ valueFieldName } "", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic)!;
447- #endif" : "" ) }
448- #if NET7_0_OR_GREATER
439+ private static extern ref { underlyingTypeFullyQualifiedName } GetValueFieldReference({ typeName } instance);" : "" ) }
440+
449441 /// <summary>
450442 /// Deserializes a plain value back into a domain object, without any validation.
451443 /// </summary>
452444 static { typeName } { Constants . SerializableDomainObjectInterfaceTypeName } <{ typeName } , { underlyingTypeFullyQualifiedName } >.Deserialize({ underlyingTypeFullyQualifiedName } value)
453445 {{
454446 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . UnsettableValue ) ? $@ "
455447 // To instead get syntax that is safe at compile time, make the Value property '{{ get; private init; }}' (or let the source generator implement it)
456- #if NET8_0_OR_GREATER
457- var result = new { typeName } (); GetValueFieldReference(result) = value; return result;
458- #else
459- var result = new { typeName } (); ValueFieldInfo.SetValue(result, value); return result;
460- #endif" : "" ) }
448+ var result = new { typeName } (); GetValueFieldReference(result) = value; return result;" : "" ) }
461449#pragma warning disable CS0618 // Obsolete constructor is intended for us
462450 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . UnsettableValue ) ? "//" : "" ) } return new { typeName } () {{ Value = value }};
463451#pragma warning restore CS0618
464452 }}
465- #endif
466453 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . DeserializeFromUnderlying ) ? "*/" : "" ) }
467454
468455 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . EqualsOperator ) ? "/*" : "" ) }
@@ -509,8 +496,6 @@ public int CompareTo({typeName}? other)
509496
510497 #region Formatting & Parsing
511498
512- #if NET7_0_OR_GREATER
513-
514499 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . FormattableToStringOverride ) ? "/*" : "" ) }
515500 public string ToString(string? format, IFormatProvider? formatProvider) =>
516501 FormattingHelper.ToString(this.Value, format, formatProvider);
@@ -545,10 +530,6 @@ public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, [Ma
545530 ({ typeName } )ParsingHelper.Parse<{ underlyingTypeFullyQualifiedName } >(s, provider);
546531 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . SpanParsableParseMethod ) ? "*/" : "" ) }
547532
548- #endif
549-
550- #if NET8_0_OR_GREATER
551-
552533 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . Utf8SpanFormattableTryFormatMethod ) ? "/*" : "" ) }
553534 public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
554535 FormattingHelper.TryFormat(this.Value, utf8Destination, out bytesWritten, format, provider);
@@ -566,8 +547,6 @@ public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provid
566547 ({ typeName } )ParsingHelper.Parse<{ underlyingTypeFullyQualifiedName } >(utf8Text, provider);
567548 { ( existingComponents . HasFlags ( WrapperValueObjectTypeComponents . Utf8SpanParsableParseMethod ) ? "*/" : "" ) }
568549
569- #endif
570-
571550 #endregion
572551 }}
573552}}
0 commit comments