Emulate C++'s typedefs with structs
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by tracing the H5F.create and H5F.get_filesize declarations and their current Int32 return types. Review how version-dependent hid_t values are represented across the P/Invoke API, then determine the affected callers and tests. Done means distinct marshable wrapper types preserve the return semantics and hid_t width while improving IntelliSense.
Written by the indexing model from the issue text.
Description
At the current state e.g. the functions H5F.create( .. ) and H5F.get_filesize( .. ) both return Int32 even though create returns an actual id and get_filesize only indicates if there was an error. So the real meanings are lost in C# when using IntelliSense.


I suggest to wrap the values into structs to create marshable wrapper types to preserve the semantics that are carried by aliases (C++ typedefs).
So instead of adding a lot usings on top of every file:
using herr_t = System.Int32;
#if HDF5_VER1_10
using hid_t = System.Int64;
#else
using hid_t = System.Int32;
#endif
I would add these types ONCE into the library:
public struct herr_t
{
public System.Int32 Value;
public static implicit operator System.Int32(herr_t value) => value.Value;
}
public struct hid_t
{
#if HDF5_VER1_10
public System.Int64 Value;
public static implicit operator System.Int64( hid_t value ) => value.Value;
#else
public System.Int32 Value;
public static implicit operator System.Int32(hid_t value) => value.Value;
#endif
}
This allows would lead to much more readable IntelliSense hints and enables the use of ad-hoc polymorphism like:
public static class HdfPInvokeHelpers
{
public static void ThrowOnError(this herr_t value)
{
if (value < 0)
throw new Exception(H5EHelper.GetErrorStack().ToString());
}
public static hid_t ThrowOnError(this hid_t value)
{
if (value < 0)
throw new Exception(H5EHelper.GetErrorStack().ToString());
return value;
}
}
class Program
{
static void Main(string[] args)
{
var file = H5F.create("file.h5", H5F.ACC_RDONLY, H5P.DEFAULT, H5P.DEFAULT).ThrowOnError();
ulong size;
H5F.get_filesize(file, ref size).ThrowOnError();
}
}
Update
Missing cross-define for hid_t added.
- Dominant language
- C#
- Stars
- 87
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HDFGroup/HDF.PInvoke
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
HDFGroup/HDF.PInvoke#191 · 3 comments · 1 reaction ·
-
closedOpen
Difficulty 1/5 Under an hour Newbie friendliness 1/100
HDFGroup/HDF.PInvoke#188 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
HDFGroup/HDF.PInvoke#186 ·
-
CFD ErrorOpen
Difficulty 4/5 3-5 days Newbie friendliness 20/100
HDFGroup/HDF.PInvoke#185 · 2 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
HDFGroup/HDF.PInvoke#184 · 7 comments ·
All issues in HDFGroup/HDF.PInvoke
Similar issues
-
bug emitter:client:csharp
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/typespec#12572 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
needs-area-label
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 comment ·
Maintainers usually reply within 1 day
-
area-networking
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dotnet/aspnetcore#70545 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day