YellowDogMan.Verify.Marshaling
0.2.0
Prefix Reserved
dotnet add package YellowDogMan.Verify.Marshaling --version 0.2.0
NuGet\Install-Package YellowDogMan.Verify.Marshaling -Version 0.2.0
<PackageReference Include="YellowDogMan.Verify.Marshaling" Version="0.2.0" />
<PackageVersion Include="YellowDogMan.Verify.Marshaling" Version="0.2.0" />
<PackageReference Include="YellowDogMan.Verify.Marshaling" />
paket add YellowDogMan.Verify.Marshaling --version 0.2.0
#r "nuget: YellowDogMan.Verify.Marshaling, 0.2.0"
#:package YellowDogMan.Verify.Marshaling@0.2.0
#addin nuget:?package=YellowDogMan.Verify.Marshaling&version=0.2.0
#tool nuget:?package=YellowDogMan.Verify.Marshaling&version=0.2.0
Verify.Marshaling
When performing C# Interop/PInvoke with C++, you sometimes need to send structs from managed memory, to unmanaged memory.
In these cases .NET will perform Marshaling for you on your data. You can customize this marshaling with attributes.
Verify.Marshaling allows you to perform Snapshot Testing on the memory layouts of your structs.
This can be useful in order to compare them to their C++ equivalents, or to lock their layout between versions of a library.
Example
Given a struct:
[StructLayout(LayoutKind.Sequential)]
public struct SimpleStruct
{
[MarshalAs(UnmanagedType.I4)]
public int Test;
[MarshalAs(UnmanagedType.R4)]
public float TestF;
}
You can verify its layout with:
[TestMethod]
public async Task BasicTest()
{
await VerifyMemoryLayout(typeof(SimpleStruct));
}
Which should produce an output like:
{
FieldName: SimpleStruct,
Size: 8,
Nested: [
{
FieldName: Test,
Size: 4,
Type: Int32
},
{
FieldName: TestF,
Size: 4,
Offset: 4,
Type: Single
}
],
Type: struct
}
That can be saved as a part of your Snapshot collection, in the same way as Verify
Setup
If you're new to Verify, we recommend checking out the Verify getting started wizard.
Future Plans
Diagrams
Projects like StructLayout and even Visual Studio. Generate visual diagrams of a struct's layout.
Tooling to generate these for C# may be handy as an alternative method to verify the layout.
Formats
There are a number of tools for C++ that can examine memory layouts.
Matching these formats, may allow for automated tests that produce C++ sourced CLang dumps, that we can then compare with Verify.Marshaling snapshots. We could also convert between them.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Verify (>= 30.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release