Пример #1
0
 /// <summary>Writes the specified array into the stream.</summary>
 /// <typeparam name="T">The type of the array item.</typeparam>
 /// <param name="items">The items.</param>
 public void Write <T>(T[] items)
 {
     if (items == null)
     {
         return;
     }
     if (items.GetType().GetElementType() == typeof(string))
     {
         var hMem  = SafeHGlobalHandle.CreateFromStringList(items as string[], StringListPackMethod.Packed, CharSet, 0);
         var bytes = hMem.ToArray <byte>(hMem.Size);
         Write(bytes, 0, bytes.Length);
     }
     else
     {
         var stSize = Marshal.SizeOf(typeof(T));
         if (stSize * items.Length + Position > Capacity)
         {
             throw new ArgumentException();
         }
         for (var i = 0; i < items.Length; i++)
         {
             Marshal.StructureToPtr(items[i], PositionPtr.Offset(i * stSize), false);
         }
         Position += stSize * items.Length;
     }
 }