Open lambdageek opened 3 months ago
/cc @tmat
Note these are not P/Invokes. extern
functions dont' have any special flags set. Instead they just don't have a method body RVA (and thus no method header or IL)
Compare C.PInvoke
vs C.StaticExtern
vs C.NormalStatic
: https://sharplab.io/#v2:EYLgtghglgdgNAFxFANgHwAICYCMBYAKAwAYACDHAOgCUBXGBKMAU0oEkHmAnAewAcAytwBuUAMbMAzgG5ChDAGZyOAGzkspAMKkA3oVIHSAbQAiKFGzB8eXBAAoARAA0AmgC0AMlGAOAlAF19Q0VlNWYADwRuGHIAFlIABQ5hHgBrZjtfWQJDUiCDEIowyOi40gEECEYxAFESrhhM7Nz88iUisoA5G0gUCqrxTN0AX0JhoA
The
[UnsafeAccessorAttribute]
(API Proposal) is used onstatic extern
functions to instruct the .NET runtime to generate an accessor method to a type member that bypass the normal .NET visibility checks.With
[UnsafeAccessor]
it becomes possible to use source-generated reflection-free serializers that can serialize and deserialize fields of user-defined classes. For example, a user may add a new field_hidden
toMyClass
and the source generator will add a new accessor method toAccessHelpers
and generate a methodDeserializeMyClass
that uses the access method to populate the hidden field.Currently if the user adds a second private field
_hidden2
and the generator adds a newstatic extern
method, EnC will report a rude edit:Note that both
AccessHelpers
or thestatic extern
method could be generic:The runtime support is tracked in https://github.com/dotnet/runtime/issues/102080