/// <summary> /// Returns the current count of strings, walking the buffer, if necessary. /// </summary> /// <returns></returns> public int GetCount() { int GetCountRet = default; int l = 0; if (SafePtr.handle == IntPtr.Zero) { return(0); } if (_lpwstr) { var lpsz = new LPWSTR(); MemPtr m; lpsz._ptr = _mem.handle; do { if (Conversions.ToBoolean(lpsz.Length)) { l += 1; } lpsz._ptr = lpsz._ptr + (lpsz.Length * 2 + 2); m = lpsz._ptr; if (m.get_ShortAt(0L) == 0) { break; } }while (true); GC.SuppressFinalize(lpsz); } else { switch (SizeDescriptorLength) { case 2: { l = _mem.get_UShortAt(0L); break; } case 4: { l = (int)_mem.get_UIntegerAt(0L); break; } case 8: { l = (int)_mem.get_LongAt(0L); break; } } } GetCountRet = l; _count = l; return(GetCountRet); }
/// <summary> /// Returns the BSTR preamble count of strings from the head of the memory buffer. /// </summary> /// <returns></returns> private long BCount() { if (SafePtr is null || SafePtr.handle == IntPtr.Zero) { return(0L); } switch (SizeDescriptorLength) { case 2: { return(SafePtr.get_UShortAt(0L)); } case 4: { return(SafePtr.get_UIntegerAt(0L)); } case 8: { return((long)SafePtr.get_ULongAt(0L)); } default: { return(0L); } } }
public static object BytesToEnum(byte[] b, Type t) { SafePtr sp = b; int x = Blob.BlobTypeSize(Blob.TypeToBlobType(t.GetEnumUnderlyingType())); switch (x) { case 1: { if (Native.Unsigned(t)) { return(Enum.ToObject(t, sp[0L])); } else { return(Enum.ToObject(t, sp.get_SByteAt(0L))); } break; } case 2: { if (Native.Unsigned(t)) { return(Enum.ToObject(t, sp.get_UShortAt(0L))); } else { return(Enum.ToObject(t, sp.get_ShortAt(0L))); } break; } case 4: { if (Native.Unsigned(t)) { return(Enum.ToObject(t, sp.get_UIntegerAt(0L))); } else { return(Enum.ToObject(t, sp.get_IntegerAt(0L))); } break; } case 8: { if (Native.Unsigned(t)) { return(Enum.ToObject(t, sp.get_ULongAt(0L))); } else { return(Enum.ToObject(t, sp.get_LongAt(0L))); } break; } } return(null); }