public sealed override void Write(byte[] buffer, int offset, int count) { ContractUtils.RequiresArrayRange(buffer, offset, count, "offset", "count"); char[] charBuffer = Encoding.GetChars(buffer, offset, count); Writer.Write(charBuffer, 0, charBuffer.Length); if (!_buffered) { Writer.Flush(); } }
public sealed override int Read(byte[] buffer, int offset, int count) { if (!CanRead) { throw new InvalidOperationException(); } ContractUtils.RequiresArrayRange(buffer, offset, count, "offset", "count"); char[] charBuffer = new char[count]; int realCount = Reader.Read(charBuffer, 0, count); return(Encoding.GetBytes(charBuffer, 0, realCount, buffer, offset)); }
public static List <T> GetRange <T>(IList <T> list, int index, int count) { ContractUtils.RequiresNotNull(list, nameof(list)); ContractUtils.RequiresArrayRange(list, index, count, nameof(index), nameof(count)); List <T> result = new List <T>(count); int stop = index + count; for (int i = index; i < stop; i++) { result.Add(list[i]); } return(result); }
public static void RemoveRange <T>(IList <T> collection, int index, int count) { ContractUtils.RequiresNotNull(collection, nameof(collection)); ContractUtils.RequiresArrayRange(collection, index, count, nameof(index), nameof(count)); if (collection is List <T> list) { list.RemoveRange(index, count); } else { for (int i = index + count - 1; i >= index; i--) { collection.RemoveAt(i); } } }
public static void RemoveRange <T>(IList <T> collection, int index, int count) { ContractUtils.RequiresNotNull(collection, "collection"); ContractUtils.RequiresArrayRange(collection, index, count, "index", "count"); List <T> list = collection as List <T>; if (list != null) { list.RemoveRange(index, count); } else { for (int i = index + count - 1; i >= index; i--) { collection.RemoveAt(i); } } }
public static int GetValueHashCode <T>(this T[] array, int start, int count) { ContractUtils.RequiresNotNull(array, nameof(array)); ContractUtils.RequiresArrayRange(array.Length, start, count, nameof(start), nameof(count)); if (count == 0) { return(0); } int result = array[start].GetHashCode(); for (int i = 1; i < count; i++) { result = ((result << 5) | (result >> 27)) ^ array[start + i].GetHashCode(); } return(result); }