RequiresInInclusiveRange() public static method

public static RequiresInInclusiveRange ( int start, int length ) : void
start int
length int
return void
コード例 #1
0
        public static void Write <[Primitive] T>(this Span <byte> slice, T value)
            where T : struct
        {
            Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length);
            Span <T> castedSlice = slice.Cast <byte, T>();

            castedSlice[0] = value;
        }
コード例 #2
0
ファイル: SpanExtensions.cs プロジェクト: ravimeda/corefxlab
 public static ReadOnlySpan <char> Slice(this string str, int start, int length)
 {
     Contract.Requires(str != null);
     Contract.RequiresInInclusiveRange(start, length, (uint)str.Length);
     return(new ReadOnlySpan <char>(
                str,
                new UIntPtr((uint)(SpanHelpers.OffsetToStringData + (start * sizeof(char)))),
                length
                ));
 }
コード例 #3
0
 public ReadOnlySpan(T[] array, int start, int length)
 {
     Contract.Requires(array != null);
     Contract.RequiresInInclusiveRange(start, length, (uint)array.Length);
     if (start < array.Length)
     {
         Object = array;
         Offset = UnsafeUtilities.GetElementAddress <T>((UIntPtr)SpanHelpers <T> .OffsetToArrayData, (UIntPtr)start);
         Length = length;
     }
     else
     {
         Object = null;
         Offset = UIntPtr.Zero;
         Length = 0;
     }
 }
コード例 #4
0
ファイル: Slice.cs プロジェクト: shuningzhou/slice.net
 /// <summary>
 /// Creates a new slice over the portion of the target array beginning
 /// at 'start' index and ending at 'end' index (exclusive).
 /// </summary>
 /// <param name="array">The target array.</param>
 /// <param name="start">The index at which to begin the slice.</param>
 /// <param name="end">The index at which to end the slice (exclusive).</param>
 /// <exception cref="System.ArgumentException">
 /// Thrown if the 'array' parameter is null.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// Thrown when the specified start or end index is not in range (&lt;0 or &gt;&eq;length).
 /// </exception>
 public Slice(T[] array, int start, int end)
 {
     Contract.Requires(array != null);
     Contract.RequiresInInclusiveRange(start, array.Length);
     if (start < array.Length)
     {
         m_object = array;
         m_offset = new UIntPtr(
             (uint)(SliceHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>())));
         Length = end - start;
     }
     else
     {
         m_object = null;
         m_offset = UIntPtr.Zero;
         Length   = 0;
     }
 }
コード例 #5
0
 public ReadOnlySpan(T[] array, int start, int length)
 {
     Contract.Requires(array != null);
     Contract.RequiresInInclusiveRange(start, length, (uint)array.Length);
     if (start < array.Length)
     {
         Object = array;
         Offset = new UIntPtr(
             (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>())));
         Length = length;
     }
     else
     {
         Object = null;
         Offset = UIntPtr.Zero;
         Length = 0;
     }
 }
コード例 #6
0
ファイル: Span.cs プロジェクト: steveruckdashel/corefxlab
 /// <summary>
 /// Creates a new span over the portion of the target array beginning
 /// at 'start' index.
 /// </summary>
 /// <param name="array">The target array.</param>
 /// <param name="start">The index at which to begin the span.</param>
 /// <exception cref="System.ArgumentException">
 /// Thrown if the 'array' parameter is null.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// Thrown when the specified start index is not in range (&lt;0 or &gt;&eq;length).
 /// </exception>
 // TODO: Should we have this overload? It is really confusing when you also have Span(T* array, int length)
 //       While with Slice it makes sense it might not in here.
 internal Span(T[] array, int start)
 {
     Contract.Requires(array != null);
     Contract.RequiresInInclusiveRange(start, array.Length);
     if (start < array.Length)
     {
         _object = array;
         _offset = new UIntPtr(
             (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>())));
         Length = array.Length - start;
     }
     else
     {
         _object = null;
         _offset = UIntPtr.Zero;
         Length  = 0;
     }
 }
コード例 #7
0
ファイル: Span.cs プロジェクト: sharmavishalvk/corefxlab
 internal Span(T[] array, int start)
 {
     Contract.Requires(array != null);
     Contract.Requires(default(T) != null || array.GetType() == typeof(T[]));
     Contract.RequiresInInclusiveRange(start, (uint)array.Length);
     if (start < array.Length)
     {
         Object = array;
         Offset = UnsafeUtilities.GetElementAddress <T>((UIntPtr)SpanHelpers <T> .OffsetToArrayData, (UIntPtr)start);
         Length = array.Length - start;
     }
     else
     {
         Object = null;
         Offset = UIntPtr.Zero;
         Length = 0;
     }
 }
コード例 #8
0
ファイル: ReadOnlySpan.cs プロジェクト: SedarG/corefxlab
 internal ReadOnlySpan(T[] array, int start)
 {
     Contract.Requires(array != null);
     Contract.RequiresInInclusiveRange(start, (uint)array.Length);
     if (start < array.Length)
     {
         Object = array;
         Offset = new UIntPtr(
             (uint)(SpanHelpers <T> .OffsetToArrayData + (start * UnsafeUtilities.SizeOf <T>())));
         Length = array.Length - start;
     }
     else
     {
         Object = null;
         Offset = UIntPtr.Zero;
         Length = 0;
     }
 }
コード例 #9
0
 internal Span(T[] array, int start)
 {
     Contract.Requires(array != null);
     Contract.Requires(default(T) != null || array.GetType() == typeof(T[]));
     Contract.RequiresInInclusiveRange(start, (uint)array.Length);
     if (start < array.Length)
     {
         Object = array;
         Offset = new UIntPtr(
             (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>())));
         Length = array.Length - start;
     }
     else
     {
         Object = null;
         Offset = UIntPtr.Zero;
         Length = 0;
     }
 }
コード例 #10
0
ファイル: SpanExtensions.cs プロジェクト: ravimeda/corefxlab
 public static T Read <[Primitive] T>(this ReadOnlySpan <byte> slice)
     where T : struct
 {
     Contract.RequiresInInclusiveRange(PtrUtils.SizeOf <T>(), (uint)slice.Length);
     return(PtrUtils.Get <T>(slice.Object, slice.Offset, (UIntPtr)0));
 }
コード例 #11
0
 public Span <T> Slice(int start)
 {
     Contract.RequiresInInclusiveRange(start, (uint)Length);
     return(new Span <T>(Object, Offset + (start * UnsafeUtilities.SizeOf <T>()), Length - start));
 }
コード例 #12
0
ファイル: Span.cs プロジェクト: sharmavishalvk/corefxlab
 public Span <T> Slice(uint start, uint length)
 {
     Contract.RequiresInInclusiveRange(start, length, (uint)Length);
     return(new Span <T>(
                Object, UnsafeUtilities.GetElementAddress <T>(Offset, (UIntPtr)start), (int)length));
 }
コード例 #13
0
 public Span <T> Slice(uint start)
 {
     Contract.RequiresInInclusiveRange(start, (uint)Length);
     return(new Span <T>(Object, Offset + (((int)start) * PtrUtils.SizeOf <T>()), Length - (int)start));
 }
コード例 #14
0
 public static T Read <[Primitive] T>(this ReadOnlySpan <byte> slice)
     where T : struct
 {
     Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length);
     return(Unsafe.As <byte, T>(ref slice.DangerousGetPinnableReference()));
 }
コード例 #15
0
 public ReadOnlySpan <T> Slice(uint start, uint length)
 {
     Contract.RequiresInInclusiveRange(start, length, (uint)Length);
     return(new ReadOnlySpan <T>(
                Object, Offset + (((int)start) * PtrUtils.SizeOf <T>()), (int)length));
 }
コード例 #16
0
 public ReadOnlySpan <T> Slice(uint start)
 {
     Contract.RequiresInInclusiveRange(start, (uint)Length);
     return(new ReadOnlySpan <T>(Object, UnsafeUtilities.GetElementAddress <T>(Offset, (UIntPtr)start), Length - (int)start));
 }
コード例 #17
0
 public Span <T> Slice(int start, int length)
 {
     Contract.RequiresInInclusiveRange(start, length, (uint)Length);
     return(new Span <T>(
                Object, Offset + (start * PtrUtils.SizeOf <T>()), length));
 }
コード例 #18
0
ファイル: Span.cs プロジェクト: IDisposable/corefxlab
 /// <summary>
 /// Forms a slice out of the given span, beginning at 'start', and
 /// ending at 'end' (exclusive).
 /// </summary>
 /// <param name="start">The index at which to begin this slice.</param>
 /// <param name="end">The index at which to end this slice (exclusive).</param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// Thrown when the specified start or end index is not in range (&lt;0 or &gt;&eq;length).
 /// </exception>
 public Span <T> Slice(int start, int end)
 {
     Contract.RequiresInInclusiveRange(start, end, Length);
     return(new Span <T>(
                m_object, m_offset + (start * PtrUtils.SizeOf <T>()), end - start));
 }
コード例 #19
0
ファイル: SpanExtensions.cs プロジェクト: ravimeda/corefxlab
 public static void Write <[Primitive] T>(this Span <byte> slice, T value)
     where T : struct
 {
     Contract.RequiresInInclusiveRange(PtrUtils.SizeOf <T>(), (uint)slice.Length);
     PtrUtils.Set(slice.Object, slice.Offset, (UIntPtr)0, value);
 }
コード例 #20
0
 public Span <T> Slice(uint start, uint length)
 {
     Contract.RequiresInInclusiveRange(start, length, (uint)Length);
     return(new Span <T>(
                Object, Offset + (((int)start) * UnsafeUtilities.SizeOf <T>()), (int)length));
 }
コード例 #21
0
 public ReadOnlySpan <T> Slice(int start)
 {
     Contract.RequiresInInclusiveRange(start, (uint)Length);
     return(new ReadOnlySpan <T>(
                Object, Offset + (start * PtrUtils.SizeOf <T>()), Length - start));
 }
コード例 #22
0
ファイル: ReadOnlySpan.cs プロジェクト: SedarG/corefxlab
 public ReadOnlySpan <T> Slice(int start, int length)
 {
     Contract.RequiresInInclusiveRange(start, length, (uint)Length);
     return(new ReadOnlySpan <T>(
                Object, Offset + (start * UnsafeUtilities.SizeOf <T>()), length));
 }
コード例 #23
0
 public static T Read <[Primitive] T>(this ReadOnlySpan <byte> slice)
     where T : struct
 {
     Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length);
     return(slice.Cast <byte, T>()[0]);
 }
コード例 #24
0
 public static void Write <[Primitive] T>(this Span <byte> slice, T value)
     where T : struct
 {
     Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length);
     Unsafe.WriteUnaligned <T>(ref slice.DangerousGetPinnableReference(), value);
 }