使用 NUGET HDF.P/Invoke 的 C# 中的 "using ???" 语句是什么?
What is the "using ???" statement in a C# that uses NUGET HDF.P/Invoke?
我需要放在 C# class 文件顶部的 "using ???" 语句是什么,以便构建 GitHub > HDF.PInvoke > 食谱代码片段?
例如,如果我将下面的食谱片段粘贴到 C# class,它不会生成,因为我假设没有 "using" 语句,并生成此错误:
"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);
}
}
好像
using HDF.PInvoke;
在此处查看单元测试用例
https://github.com/HDFGroup/HDF.PInvoke/tree/master/UnitTests/H5ATest
我需要放在 C# class 文件顶部的 "using ???" 语句是什么,以便构建 GitHub > HDF.PInvoke > 食谱代码片段?
例如,如果我将下面的食谱片段粘贴到 C# class,它不会生成,因为我假设没有 "using" 语句,并生成此错误:
"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);
}
}
好像
using HDF.PInvoke;
在此处查看单元测试用例
https://github.com/HDFGroup/HDF.PInvoke/tree/master/UnitTests/H5ATest