/// <summary> /// Add an array of strings to the end of the collection. /// </summary> /// <param name="values">Array of strings.</param> public void AddStrings(string[] values) { if (values is null) { return; } int sdl = SizeDescriptorLength; int dl = sdl * values.Length; foreach (var s in values) { dl += s.Length * 2; } if (_lpwstr) { dl += 2 * values.Length; } long sl; IntPtr sp; long oldLen; if (SafePtr.Length <= 0L) { SafePtr.Length = sdl; } oldLen = SafePtr.Length; switch (sdl) { case 2: { SafePtr.get_UShortAt(0L); break; } case 4: { SafePtr.get_UIntegerAt(0L); break; } case 8: { SafePtr.get_ULongAt(0L); break; } } SafePtr.Length += dl; sp = SafePtr.handle + (int)oldLen; int oi; if (_index is null) { oi = 0; _index = new IntPtr[values.Length]; } else { oi = _index.Length; Array.Resize(ref _index, _index.Length + (values.Length - 1) + 1); } if (_lpwstr) { foreach (var s in values) { sl = s.Length; _index[oi] = sp; oi += 1; QuickCopyObject <string>(sp, s, (uint)(sl + sl)); sp = sp + (int)(sl + sl); MemPtr mm = sp; mm.set_ShortAt(0L, 0); sp = sp + 2; } } else { foreach (var s in values) { sl = s.Length; _index[oi] = sp; oi += 1; MemPtr mm = sp; switch (sdl) { case 2: { mm.set_UShortAt(0L, (ushort)sl); break; } case 4: { mm.set_UIntegerAt(0L, (uint)sl); break; } case 8: { mm.set_LongAt(0L, sl); break; } } sp = sp + sdl; QuickCopyObject <string>(sp, s, (uint)(sl + sl)); sp = sp + (int)(sl + sl); } } _count = _index.Length; }
/// <summary> /// Add a string to the end of the collection. /// </summary> /// <param name="value">The string to add.</param> public void AddString(string value) { int ol; if (_lpwstr) { ol = (int)(_mem.Length - 2L); if (ol <= 0) { _mem.Length = 2L; ol = 0; } _mem.Length += value.Length + 2; QuickCopyObject <string>(IntPtr.Add(_mem.handle, ol), value, (uint)(value.Length * 2)); } else { int l = SizeDescriptorLength + value.Length * 2; if (_mem.Length == 0L) { _mem.Length = SizeDescriptorLength; } ol = (int)_mem.Length; switch (SizeDescriptorLength) { case 1: { _mem[0L] = (byte)(_mem[0L] + 1); break; } case 2: { _mem.get_ShortAt(0L); break; } case 4: { _mem.get_UIntegerAt(0L); break; } } _mem.Length += l; IntPtr ap; IntPtr at; ap = IntPtr.Add(_mem.handle, ol); at = IntPtr.Add(ap, SizeDescriptorLength); MemPtr mm = ap; switch (SizeDescriptorLength) { case 2: { mm.set_UShortAt(0L, (ushort)value.Length); break; } case 4: { mm.set_UIntegerAt(0L, (uint)value.Length); break; } case 8: { mm.set_LongAt(0L, value.Length); break; } } QuickCopyObject <string>(at, value, (uint)(value.Length * 2)); } if (!_dynamic) { _index = new IntPtr[_count + 1]; _index[_count] = IntPtr.Add(_mem.handle, ol); _count += 1; } }