-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add inline array marshaller sample to our custom marshalling sample.
- Loading branch information
1 parent
9e63fe9
commit 8a201e3
Showing
5 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
core/interop/source-generation/custom-marshalling/src/custommarshalling/ErrorBuffer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.Marshalling; | ||
|
||
namespace CustomMarshalling | ||
{ | ||
[NativeMarshalling(typeof(ErrorBufferMarshaller))] | ||
[InlineArray(4)] | ||
public struct ErrorBuffer | ||
{ | ||
private ErrorData _data; | ||
} | ||
|
||
[CustomMarshaller(typeof(ErrorBuffer), MarshalMode.ManagedToUnmanagedIn, typeof(ErrorBufferMarshaller))] | ||
public static class ErrorBufferMarshaller | ||
{ | ||
[InlineArray(4)] | ||
public struct ErrorBufferUnmanaged | ||
{ | ||
private ErrorDataMarshaller.ErrorDataUnmanaged _data; | ||
} | ||
|
||
public static ErrorBufferUnmanaged ConvertToUnmanaged(ErrorBuffer managed) | ||
{ | ||
ErrorBufferUnmanaged unmanaged = new(); | ||
for (int i = 0; i < 4; i++) | ||
{ | ||
unmanaged[i] = ErrorDataMarshaller.ConvertToUnmanaged(managed[i]); | ||
} | ||
return unmanaged; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters