private void SerializeContainer(IEnumerable e, Type elementType, IDataAdapter data) { if (settings.PrimitiveAsBase64 && elementType.IsPrimitive) { int size = ByteUtils.GetSizeOf(elementType); int count = 0; // ReSharper disable once UnusedVariable foreach (object o in e) { count++; } Action <byte[], int, object> writer = ByteUtils.GetBinaryWriter(elementType); byte[] buffer = new byte[size * count]; int index = 0; foreach (object o in e) { writer(buffer, index, o); index += size; } data.SetStringValue(Convert.ToBase64String(buffer)); } else { IDataArray array = data.AddArray(); foreach (object o in e) { SerializeSubValue(elementType, o, array.AddArrayValue(), null); } } haveContainers = true; }
private void SerializeArrayRank(Array array, Type elementType, int[] coords, int r, IDataAdapter data) { if (r == coords.Length - 1) { if (settings.PrimitiveAsBase64 && elementType.IsPrimitive) { int size = ByteUtils.GetSizeOf(elementType); int count = array.GetLength(r); Action <byte[], int, object> writer = ByteUtils.GetBinaryWriter(elementType); byte[] buffer = new byte[size * count]; int index = 0; for (int i = 0; i < count; i++) { coords[r] = i; writer(buffer, index, array.GetValue(coords)); index += size; } data.SetStringValue(Convert.ToBase64String(buffer)); } else { IDataArray a = data.AddArray(); for (int i = 0; i < array.GetLength(r); i++) { coords[r] = i; SerializeSubValue(elementType, array.GetValue(coords), a.AddArrayValue(), null); } } } else { IDataArray a = data.AddArray(); for (int i = 0; i < array.GetLength(r); i++) { coords[r] = i; SerializeArrayRank(array, elementType, coords, r + 1, a.AddArrayValue()); } } }