static extern Boolean WriteFile( IntPtr hFile, [In, Out] ArrayWithOffset lpBuffer, UInt32 nNumberOfBytesToWrite, out UInt32 lpNumberOfBytesWritten, IntPtr lpOverlapped );
static extern Boolean ReadFile( IntPtr hFile, [In, Out] ArrayWithOffset lpBuffer, UInt32 nNumberOfBytesToRead, out UInt32 lpNumberOfBytesRead, IntPtr lpOverlapped );
public void Ctor_Array_Offset(object array, int offset, int expectedHashCode) { var arrayWithOffset = new ArrayWithOffset(array, offset); Assert.Equal(array, arrayWithOffset.GetArray()); Assert.Equal(offset, arrayWithOffset.GetOffset()); Assert.Equal(expectedHashCode, arrayWithOffset.GetHashCode()); }
public void Equals_Object_ReturnsExpected(ArrayWithOffset arrayWithOffset, object other, bool expected) { Assert.Equal(expected, arrayWithOffset.Equals(other)); if (other is ArrayWithOffset otherArrayWithOffset) { Assert.Equal(expected, arrayWithOffset == otherArrayWithOffset); Assert.Equal(!expected, arrayWithOffset != otherArrayWithOffset); } }
static void testCharArrayWithOffset() { char[] c = GetInvalidArray(); ArrayWithOffset arrWOff_0 = new ArrayWithOffset(c, 0); Assert.True(Char_InOut_ArrayWithOffset(arrWOff_0)); c = GetValidArray(); ArrayWithOffset arrWOff_1 = new ArrayWithOffset(c, 1); Assert.True(Char_InOut_ArrayWithOffset(arrWOff_1)); }
static void testCharArrayWithOffset() { char[] c = GetInvalidArray(); ArrayWithOffset arrWOff_0 = new ArrayWithOffset(c, 0); Assert.IsTrue(Char_InOut_ArrayWithOffset(arrWOff_0), "[Error] Location ctlpsawo11"); c = GetValidArray(); ArrayWithOffset arrWOff_1 = new ArrayWithOffset(c, 1); Assert.IsTrue(Char_InOut_ArrayWithOffset(arrWOff_1), "[Error] Location ctlpsawo22"); }
// Determine if two objects are equal. public override bool Equals(Object obj) { if (obj is ArrayWithOffset) { ArrayWithOffset other = (ArrayWithOffset)obj; return(array == other.array && offset == other.offset); } else { return(false); } }
public void Read(Byte[] outBuffer, int index, int count) { UInt32 bytesRead; while (0 < count) { ArrayWithOffset arr = new ArrayWithOffset(outBuffer, index); if (!ReadFile(m_ReadPipe, arr, (UInt32)count, out bytesRead, IntPtr.Zero)) throw new System.ApplicationException(); index += (int)bytesRead; count -= (int)bytesRead; } }
public void Write(Byte[] buffer, int index, int count) { UInt32 bytesWritten = 0; while(0 < count) { ArrayWithOffset arr = new ArrayWithOffset(buffer, index); if(!WriteFile(m_WritePipe, arr, (uint)count, out bytesWritten, IntPtr.Zero)) throw new System.ApplicationException(); index += (int)bytesWritten; count -= (int)bytesWritten; } }
public static int Main() { try { Span <int> expected = new int[] { 1, 2, 3, 4, 5, 6 }; Span <int> newValue = new int[] { 7, 8, 9, 10, 11, 12 }; for (int i = 0; i < expected.Length; i++) { int[] array = new int[] { 1, 2, 3, 4, 5, 6 }; ArrayWithOffset offset = new ArrayWithOffset(array, i * 4); // The offset parameter in ArrayWithOffset is a byte-offset, not an element offset. fixed(int *expectedSubArray = expected.Slice(i)) fixed(int *newValueSubArray = newValue.Slice(i)) { Assert.True(ArrayWithOffsetNative.Marshal_InOut(expectedSubArray, offset, expected.Length - i, newValueSubArray), $"Native call failed with element offset {i}."); } for (int j = 0; j < i; j++) { Assert.Equal(expected[j], array[j]); } for (int j = i; j < array.Length; j++) { Assert.Equal(newValue[j], array[j]); } } ArrayWithOffset arrayWithOffset = new ArrayWithOffset(new int[] { 1 }, 0); Assert.Throws <MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid(arrayWithOffset)); Assert.Throws <MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid(ref arrayWithOffset)); Assert.Throws <MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid_Return()); } catch (Exception e) { Console.WriteLine(e); return(101); } return(100); }
public static extern bool Marshal_InOut(int *expected, [In, Out] ArrayWithOffset actual, int numElements, int *newValue);
public static extern bool Char_InOut_ArrayWithOffset([In, Out] ArrayWithOffset charArrayWithOffset);
public static bool op_Inequality(ArrayWithOffset a, ArrayWithOffset b) {}
public static bool op_Inequality(ArrayWithOffset a, ArrayWithOffset b) { }
public bool Equals(ArrayWithOffset obj) { }
public static extern bool Marshal_Invalid(ArrayWithOffset invalidArray);
public static extern bool Marshal_Invalid(ref ArrayWithOffset array);
public bool Equals(ArrayWithOffset obj) {}