You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, this new design continues to use the existing policy for defining "blittable" types as described in the V1 design. The rest of this document will describe the custom user-defined marshalling rules.
195
195
196
-
In the new design, the user will first define an "entry-point type" that represents a marshalling concept. For example, if we are marshalling a `string` to a native UTF-8 encoded string, we might call the marshaller `Utf8StringMarshaller`. This new type will be a `static class`. The developer will then use the `ManagedToUnmanagedMarshallersAttribute`, `UnmanagedToManagedMarshallersAttribute`, and `ElementMarshallerAttribute`to specify which "marshaller implementation type" will be used to actually provide the marshalling. If an attribute is missing or a property on the attribute is set to `null` or left unset, this marshaller will not support marshalling in that scenario. A single type can be specified multiple times if it provides the marshalling support for multiple scenarios.
196
+
In the new design, the user will first define an "entry-point type" that represents a marshalling concept. For example, if we are marshalling a `string` to a native UTF-8 encoded string, we might call the marshaller `Utf8StringMarshaller`. This entry-point type must be a `static class` or a `struct`. The developer will then use the `CustomMarshallerAttribute`to specify which "marshaller implementation type" will be used to actually provide the marshalling for a `MarshalMode`. If an attribute is missing or a property on the attribute is set to `null` or left unset, this marshaller will not support marshalling in that scenario. If the marshaller implementation type is considered stateless if it is a `static class` and stateful if it is a `struct`. A single type can be specified multiple times if it provides the marshalling support for multiple scenarios.
197
197
198
198
To avoid confusion around when each marshaller applies, we define when the marshallers apply based on the C# syntax used. This helps reduce the concept load as developers don't need to remember the mapping between the previous design's `CustomTypeMarshallerDirection` enum member and the C# keyword used for a parameter, which do not match in a Reverse P/Invoke-like scenario.
199
199
@@ -220,8 +220,8 @@ The type `TNative` can be any `unmanaged` type. It represents whatever unmanaged
@@ -423,7 +423,7 @@ static class TMarshaller<T, U, V...>
423
423
424
424
## Linear (Array-like) Collection Marshaller Shapes
425
425
426
-
We'll continue with the collection marshaller shapes. These marshaller shapes support marshalling the structure of a collection of values, where the values themselves are marshalled with marshallers of their own (using the marshaller provided in the `ElementMarshallerAttribute`). This construction allows us to compose our marshallers and to easily support arrays of custom types without needing to implement a separate marshaller for each element type.
426
+
We'll continue with the collection marshaller shapes. These marshaller shapes support marshalling the structure of a collection of values, where the values themselves are marshalled with marshallers of their own (using the marshaller provided for `MarshalMode.Element*`). This construction allows us to compose our marshallers and to easily support arrays of custom types without needing to implement a separate marshaller for each element type.
427
427
428
428
Each of these shapes will support marshalling the following type:
429
429
@@ -502,13 +502,13 @@ static class TMarshaller<T, U, V..., TUnmanagedElement> where TUnmanagedElement
502
502
{
503
503
publicstaticclassNativeToManaged
504
504
{
505
-
publicstaticTCollectionAllocateContainerForManagedElements(TNativeunmanaged, intlength); // Can throw exceptions
505
+
publicstaticTCollectionAllocateContainerForManagedElements(TNativeunmanaged, intnumElements); // Can throw exceptions
506
506
507
-
publicstaticSpan<TManagedElement> GetManagedValuesDestination(T[]managed) =>managed; // Can throw exceptions
507
+
publicstaticSpan<TManagedElement> GetManagedValuesDestination(TCollectionmanaged) =>managed; // Can throw exceptions
508
508
509
509
publicstaticReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(TNativeunmanaged, intnumElements); // Can throw exceptions
510
510
511
-
publicstaticvoidFree(TNativenative); // Optional. Should not throw exceptions.
511
+
publicstaticvoidFree(TNativeunmanaged); // Optional. Should not throw exceptions.
512
512
}
513
513
}
514
514
@@ -525,13 +525,13 @@ static class TMarshaller<T, U, V..., TUnmanagedElement> where TUnmanagedElement
525
525
{
526
526
publicstaticclassNativeToManaged
527
527
{
528
-
publicstaticTCollectionAllocateContainerForManagedElementsFinally(TNativeunmanaged, intlength); // Should not throw exceptions other than OutOfMemoryException.
528
+
publicstaticTCollectionAllocateContainerForManagedElementsFinally(TNativeunmanaged, intnumElements); // Should not throw exceptions other than OutOfMemoryException.
529
529
530
-
publicstaticSpan<TManagedElement> GetManagedValuesDestination(T[]managed) =>managed; // Can throw exceptions
530
+
publicstaticSpan<TManagedElement> GetManagedValuesDestination(TCollectionmanaged) =>managed; // Can throw exceptions
531
531
532
532
publicstaticReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(TNativeunmanaged, intnumElements); // Can throw exceptions
533
533
534
-
publicstaticvoidFree(TNativenative); // Optional. Should not throw exceptions.
534
+
publicstaticvoidFree(TNativeunmanaged); // Optional. Should not throw exceptions.
535
535
}
536
536
}
537
537
@@ -571,7 +571,7 @@ static class TMarshaller<T, U, V..., TUnmanagedElement> where TUnmanagedElement
571
571
572
572
publicReadOnlySpan<TManagedElement> GetManagedValuesSource(); // Can throw exceptions.
573
573
574
-
publicSpan<byte> GetUnmanagedValuesDestination(); // Can throw exceptions.
574
+
publicSpan<TUnmanagedElement> GetUnmanagedValuesDestination(); // Can throw exceptions.
575
575
576
576
publicrefTIgnoredGetPinnableReference(); // Optional. Can throw exceptions.
577
577
@@ -603,7 +603,7 @@ static class TMarshaller<T, U, V..., TUnmanagedElement> where TUnmanagedElement
603
603
604
604
publicReadOnlySpan<TManagedElement> GetManagedValuesSource(); // Can throw exceptions.
605
605
606
-
publicSpan<byte> GetUnmanagedValuesDestination(); // Can throw exceptions.
606
+
publicSpan<TUnmanagedElement> GetUnmanagedValuesDestination(); // Can throw exceptions.
607
607
608
608
publicrefTIgnoredGetPinnableReference(); // Optional. Can throw exceptions.
609
609
@@ -631,9 +631,9 @@ static class TMarshaller<T, U, V..., TUnmanagedElement> where TUnmanagedElement
631
631
632
632
publicvoidFromUnmanaged(TNativevalue); // Should not throw exceptions.
633
633
634
-
publicReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(intlength); // Can throw exceptions.
634
+
publicReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(intnumElements); // Can throw exceptions.
635
635
636
-
publicSpan<TManagedElement> GetManagedValuesDestination(intlength); // Can throw exceptions.
636
+
publicSpan<TManagedElement> GetManagedValuesDestination(intnumElements); // Can throw exceptions.
637
637
638
638
publicTCollectionToManaged(); // Can throw exceptions
639
639
@@ -656,9 +656,9 @@ static class TMarshaller<T, U, V..., TUnmanagedElement> where TUnmanagedElement
656
656
657
657
publicvoidFromUnmanaged(TNativevalue); // Should not throw exceptions.
658
658
659
-
publicReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(intlength); // Can throw exceptions.
659
+
publicReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(intnumElements); // Can throw exceptions.
660
660
661
-
publicSpan<TManagedElement> GetManagedValuesDestination(intlength); // Can throw exceptions.
661
+
publicSpan<TManagedElement> GetManagedValuesDestination(intnumElements); // Can throw exceptions.
662
662
663
663
publicTCollectionToManagedFinally(); // Can throw exceptions
0 commit comments