Search code examples
c#.netpinvokehdf5

What is the "using ???" statement in a C# that uses NUGET HDF.P/Invoke?


What is the "using ???" statement that I need to put at the top of my C# class file, in order to build a GitHub > HDF.PInvoke > cookbook code snippets?

For example, if I paste the cookbook snippet below into a C# class, it doesn't build because, I assume, there is no "using" statement, and generates this error:

"H5A doesn't exist in the current context."

private bool ReadStringAttribute(hid_t objectId, string title, out string value)
{
  value = "";

  hid_t attributeId = 0;
  hid_t typeId = 0;

  try
  {
    attributeId = H5A.open(objectId, title);
    typeId = H5A.get_type(attributeId);
    var sizeData = H5T.get_size(typeId);
    var size = sizeData.ToInt32();
    byte[] strBuffer = new byte[size];

    var aTypeMem = H5T.get_native_type(typeId, H5T.direction_t.ASCEND);
    GCHandle pinnedArray = GCHandle.Alloc(strBuffer, GCHandleType.Pinned);
    H5A.read(attributeId, aTypeMem, pinnedArray.AddrOfPinnedObject());
    pinnedArray.Free();
    H5T.close(aTypeMem);

    value = System.Text.ASCIIEncoding.ASCII.GetString(strBuffer);

    return true;
  }
  catch (Exception ex)
  {
    return false;
  }
  finally
  {
    if (attributeId != null) H5A.close(attributeId);
    if (typeId != null) H5T.close(typeId);
  }
}

Solution

  • It seems like

    using HDF.PInvoke;
    

    Look into unit test cases here

    https://github.com/HDFGroup/HDF.PInvoke/tree/master/UnitTests/H5ATest