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

            Assert.True(immutable.IsDefault);
        }
        public void DangerousGetUnderlyingArray()
        {
            ImmutableArray <int> immutable = ImmutableArray.Create(1, 2, 3);

            int[] array = ImmutableArrayInterop.DangerousGetUnderlyingArray(immutable);

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

            array[0] = 9;

            Assert.Equal(9, immutable[0]);
        }
        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]);
        }
Exemple #4
0
 /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Range specified by <paramref name="start"/> and <paramref name="byteCount"/> falls outside of the bounds of the <paramref name="buffer"/>.</exception>
 /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception>
 public void WriteBytes(ImmutableArray <byte> buffer, int start, int byteCount)
 {
     WriteBytes(ImmutableArrayInterop.DangerousGetUnderlyingArray(buffer), start, byteCount);
 }
Exemple #5
0
        /// <exception cref="ArgumentOutOfRangeException">Range specified by <paramref name="start"/> and <paramref name="byteCount"/> falls outside of the bounds of the buffer content.</exception>
        /// <exception cref="InvalidOperationException">Content is not available, the builder has been linked with another one.</exception>
        public ImmutableArray <byte> ToImmutableArray(int start, int byteCount)
        {
            var array = ToArray(start, byteCount);

            return(ImmutableArrayInterop.DangerousToImmutableArray(ref array));
        }
        public void DangerousGetUnderlyingArrayNegativeTests()
        {
            ImmutableArray <int> immutable = default(ImmutableArray <int>);

            Assert.Null(ImmutableArrayInterop.DangerousGetUnderlyingArray(immutable));
        }
 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));
 }
 public ImmutableArray <byte> GetILContent()
 {
     byte[] bytes = GetILBytes();
     return(ImmutableArrayInterop.DangerousCreateFromUnderlyingArray(ref bytes));
 }