Skip to content

Commit 5104216

Browse files
Apply suggestions from code review
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
1 parent cd0351c commit 5104216

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/design/libraries/DllImportGenerator/StructMarshalling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ partial struct TNative
5454
}
5555
```
5656

57-
The analyzer will report an error if neither the constructor nor the ToManaged method is defined. When one of those two methods is missing, the direction of marshalling (managed to native/native to managed) that relies on the missing method is considered unsupported for the corresponding managed type. The FreeNative method is only required when there are resources that need to be released.
57+
The analyzer will report an error if neither the constructor nor the `ToManaged` method is defined. When one of those two methods is missing, the direction of marshalling (managed to native/native to managed) that relies on the missing method is considered unsupported for the corresponding managed type. The `FreeNative` method is only required when there are resources that need to be released.
5858

5959

6060
> :question: Does this API surface and shape work for all marshalling scenarios we plan on supporting? It may have issues with the current "layout class" by-value `[Out]` parameter marshalling where the runtime updates a `class` typed object in place. We already recommend against using classes for interop for performance reasons and a struct value passed via `ref` or `out` with the same members would cover this scenario.
6161
6262
If the native type `TNative` also has a public `Value` property, then the value of the `Value` property will be passed to native code instead of the `TNative` value itself. As a result, the type `TNative` will be allowed to be non-blittable and the type of the `Value` property will be required to be blittable. If the `Value` property is settable, then when marshalling in the native-to-managed direction, a default value of `TNative` will have its `Value` property set to the native value. If `Value` does not have a setter, then marshalling from native to managed is not supported.
6363

64-
If a `Value` property is provided, the developer may also provide a ref-returning or readonly-ref-returning `GetPinnableReference` method. The `GetPinnableReference` method will be called before the `Value` property getter is called. The ref returned by `GetPinnableReference` will be pinned with a `fixed` statement, but the pinned will not be used (it acts exclusively as a side-effect).
64+
If a `Value` property is provided, the developer may also provide a ref-returning or readonly-ref-returning `GetPinnableReference` method. The `GetPinnableReference` method will be called before the `Value` property getter is called. The ref returned by `GetPinnableReference` will be pinned with a `fixed` statement, but the pinned value will not be used (it acts exclusively as a side-effect).
6565

6666
A `ref` or `ref readonly` typed `Value` property is unsupported. If a ref-return is required, the type author can supply a `GetPinnableReference` method on the native type to pin the desired `ref` to return and then use `System.Runtime.CompilerServices.Unsafe.AsPointer` to get a pointer from the `ref` that will have already been pinned by the time the `Value` getter is called.
6767

src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/AnalyzerReleases.Unshipped.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ DLLIMPORTGENANALYZER014 | Usage | Error | RefValuePropertyUnsuppor
2222
DLLIMPORTGENANALYZER015 | Interoperability | Disabled | ConvertToGeneratedDllImportAnalyzer
2323
DLLIMPORTGENANALYZER016 | Usage | Error | GenericTypeMustBeClosed
2424
DLLIMPORTGENANALYZER017 | Usage | Warning | GeneratedDllImportContainingTypeMissingModifiers
25-
DLLIMPORTGENANALYZER018 | Usage | Error | MarshallerGetPinnableReferenceRequiresValueProperty
25+
DLLIMPORTGENANALYZER018 | Usage | Error | MarshallerGetPinnableReferenceRequiresValueProperty

0 commit comments

Comments
 (0)