diff --git a/src/Vogen/Util.cs b/src/Vogen/Util.cs index a2ec6a7a283..b36874b6272 100644 --- a/src/Vogen/Util.cs +++ b/src/Vogen/Util.cs @@ -467,7 +467,7 @@ public static string GeneratePolyTypeAttributeIfAvailable(VogenKnownSymbols know return string.Empty; } - return @" [global::PolyType.TypeShapeAttribute(Marshaler = typeof(PolyTypeMarshaler), Kind = global::PolyType.TypeShapeKind.None)]"; + return @" [global::PolyType.TypeShapeAttribute(Marshaler = typeof(PolyTypeMarshaler))]"; } /// @@ -484,12 +484,14 @@ public static string GeneratePolyTypeMarshalerIfAvailable(VogenKnownSymbols know var underlyingType = item.UnderlyingTypeFullName; return $@" + #nullable disable [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public class PolyTypeMarshaler : global::PolyType.IMarshaler<{typeName}, {underlyingType}> + public sealed class PolyTypeMarshaler : global::PolyType.IMarshaler<{typeName}, {underlyingType}> {{ {underlyingType} global::PolyType.IMarshaler<{typeName}, {underlyingType}>.Marshal({typeName} value) => value.Value; {typeName} global::PolyType.IMarshaler<{typeName}, {underlyingType}>.Unmarshal({underlyingType} value) => From(value); - }}"; + }} + #nullable restore"; } public static string GenerateCoverageExcludeAndGeneratedCodeAttributes() => diff --git a/tests/SnapshotTests/PolyType/snapshots/snap-v8.0/PolyTypeTests.PolyType_support_is_generated_with_PolyType_reference.verified.txt b/tests/SnapshotTests/PolyType/snapshots/snap-v8.0/PolyTypeTests.PolyType_support_is_generated_with_PolyType_reference.verified.txt index 753b9c9bc80..ab28a10b23c 100644 --- a/tests/SnapshotTests/PolyType/snapshots/snap-v8.0/PolyTypeTests.PolyType_support_is_generated_with_PolyType_reference.verified.txt +++ b/tests/SnapshotTests/PolyType/snapshots/snap-v8.0/PolyTypeTests.PolyType_support_is_generated_with_PolyType_reference.verified.txt @@ -69,7 +69,7 @@ namespace generator [global::System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(MyIdDebugView))] [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] -[global::PolyType.TypeShapeAttribute(Marshaler = typeof(PolyTypeMarshaler), Kind = global::PolyType.TypeShapeKind.None)] +[global::PolyType.TypeShapeAttribute(Marshaler = typeof(PolyTypeMarshaler))] // ReSharper disable once UnusedType.Global public partial struct MyId : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable, global::System.IParsable, global::System.ISpanParsable, global::System.IUtf8SpanParsable, global::System.IFormattable, global::System.ISpanFormattable, global::System.IUtf8SpanFormattable { @@ -735,11 +735,13 @@ private readonly global::System.Diagnostics.StackTrace _stackTrace = null!; } } +#nullable disable [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public class PolyTypeMarshaler : global::PolyType.IMarshaler + public sealed class PolyTypeMarshaler : global::PolyType.IMarshaler { System.Int32 global::PolyType.IMarshaler.Marshal(MyId value) => value.Value; MyId global::PolyType.IMarshaler.Unmarshal(System.Int32 value) => From(value); } +#nullable restore } ] \ No newline at end of file