什么是“使用???”声明我需要放在我的C#类文件的顶部,以便构建一个GitHub> HDF.PInvoke> cookbook代码片段?
例如,如果我将下面的cookbook片段粘贴到C#类中,它就不会构建,因为我认为没有“using”语句,并生成此错误:
“在当前背景下,H5A不存在。”
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);
}
}
这好像是
using HDF.PInvoke;
在这里查看单元测试用例
https://github.com/HDFGroup/HDF.PInvoke/tree/master/UnitTests/H5ATest