public void DangerousCreateFromUnderlyingArrayNegativeTests()
        {
            int[] array = null;
            ImmutableArray <int> immutable = ImmutableArrayInterop.DangerousCreateFromUnderlyingArray(ref array);

            Assert.True(immutable.IsDefault);
        }
        public void DangerousCreateFromUnderlyingArray()
        {
            int[] array = new int[3] {
                1, 2, 3
            };
            int[] arrayCopy = array;
            ImmutableArray <int> immutable = ImmutableArrayInterop.DangerousCreateFromUnderlyingArray(ref array);

            // DangerousCreateFromUnderlyingArray clears the given parameter as a signal that
            // the mutable array should no longer be modified through mutable references.
            Assert.Null(array);

            Assert.Equal(3, immutable.Length);
            Assert.Equal(1, immutable[0]);
            Assert.Equal(2, immutable[1]);
            Assert.Equal(3, immutable[2]);

            arrayCopy[0] = 9;

            Assert.Equal(9, immutable[0]);
        }
Ejemplo n.º 3
0
 protected static unsafe ImmutableArray <byte> CreateImmutableArray(byte *ptr, int length)
 {
     byte[] bytes = new byte[length];
     Marshal.Copy((IntPtr)ptr, bytes, 0, length);
     return(ImmutableArrayInterop.DangerousCreateFromUnderlyingArray(ref bytes));
 }
Ejemplo n.º 4
0
 public ImmutableArray <byte> GetILContent()
 {
     byte[] bytes = GetILBytes();
     return(ImmutableArrayInterop.DangerousCreateFromUnderlyingArray(ref bytes));
 }