/// <summary>
/// 该结构类型的内存容量
/// </summary>
/// <returns></returns>
public static int MemorySize()
{
unsafe
{
return sizeof(DbfField);
}
}
/// <summary>
/// 从字节数组中装载数据
/// </summary>
/// <param name="src"></param>
public void LoadMemory(byte[] src)
{
unsafe
{
DbfField* p = (DbfField*)Marshal.UnsafeAddrOfPinnedArrayElement(src, 0);
this = *p;
}
}
/// <summary>
/// 系列化到字节数组中
/// </summary>
/// <returns></returns>
public byte[] GetMemory()
{
unsafe
{
byte[] dest = new byte[MemorySize()];
DbfField* p = (DbfField*)Marshal.UnsafeAddrOfPinnedArrayElement(dest, 0);
*p = this;
return dest;
}
}
/// <summary>
/// 产生一个新的空的该类型的字节数组
/// </summary>
/// <returns></returns>
public static byte[] NewMemory()
{
return new byte[MemorySize()];
}
#endregion
/// <summary>
/// 用指定的字节数组构造
/// </summary>
/// <param name="src"></param>
public DbfField(byte[] src)
{
this = new DbfField();
LoadMemory(src);
}
/// <summary>
/// 字段名称
/// </summary>
public string FieldName
{
get
{
fixed (DbfField* p = &this)
{
return Marshal.PtrToStringAnsi((IntPtr)p->_FieldName);
}
}
set
{
fixed (DbfField* p = &this)
{
for (int i = 0; i < MaxFieldLength; i++)
p->_FieldName[i] = 0;
byte* v = (byte*)Marshal.StringToHGlobalAnsi(value);
for (int i = 0; (i < MaxFieldLength) && (v[i] != 0); i++)
p->_FieldName[i] = v[i];
}
}
}