1- // Licensed to the .NET Foundation under one or more agreements.
2- // The .NET Foundation licenses this file to you under the MIT license.
3- // See the LICENSE file in the project root for more information.
4-
5- using System ;
1+ using System ;
62using System . IO ;
7- using System . Runtime . CompilerServices ;
83
94namespace Microsoft . Toolkit . HighPerformance . Streams
105{
116 /// <summary>
12- /// A <see cref="Stream"/> implementation wrapping a <see cref="Memory{T }"/> or <see cref="ReadOnlyMemory{T}"/> instance .
7+ /// A factory class to produce <see cref="MemoryStream{TSource }"/> instances .
138 /// </summary>
14- internal partial class MemoryStream
9+ internal static partial class MemoryStream
1510 {
11+ /// <summary>
12+ /// Throws an <see cref="ArgumentException"/> when trying to write too many bytes to the target stream.
13+ /// </summary>
14+ public static void ThrowArgumentExceptionForEndOfStreamOnWrite ( )
15+ {
16+ throw new ArgumentException ( "The current stream can't contain the requested input data." ) ;
17+ }
18+
19+ /// <summary>
20+ /// Throws a <see cref="NotSupportedException"/> when trying to set the length of the stream.
21+ /// </summary>
22+ public static void ThrowNotSupportedExceptionForSetLength ( )
23+ {
24+ throw new NotSupportedException ( "Setting the length is not supported for this stream." ) ;
25+ }
26+
27+ /// <summary>
28+ /// Throws an <see cref="ArgumentException"/> when using an invalid seek mode.
29+ /// </summary>
30+ /// <returns>Nothing, as this method throws unconditionally.</returns>
31+ public static long ThrowArgumentExceptionForSeekOrigin ( )
32+ {
33+ throw new ArgumentException ( "The input seek mode is not valid." , "origin" ) ;
34+ }
35+
1636 /// <summary>
1737 /// Throws an <see cref="ArgumentOutOfRangeException"/> when setting the <see cref="Stream.Position"/> property.
1838 /// </summary>
19- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
2039 private static void ThrowArgumentOutOfRangeExceptionForPosition ( )
2140 {
22- throw new ArgumentOutOfRangeException ( nameof ( Position ) , "The value for the property was not in the valid range." ) ;
41+ throw new ArgumentOutOfRangeException ( nameof ( Stream . Position ) , "The value for the property was not in the valid range." ) ;
2342 }
2443
2544 /// <summary>
2645 /// Throws an <see cref="ArgumentNullException"/> when an input buffer is <see langword="null"/>.
2746 /// </summary>
28- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
2947 private static void ThrowArgumentNullExceptionForBuffer ( )
3048 {
3149 throw new ArgumentNullException ( "buffer" , "The buffer is null." ) ;
@@ -34,7 +52,6 @@ private static void ThrowArgumentNullExceptionForBuffer()
3452 /// <summary>
3553 /// Throws an <see cref="ArgumentOutOfRangeException"/> when the input count is negative.
3654 /// </summary>
37- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
3855 private static void ThrowArgumentOutOfRangeExceptionForOffset ( )
3956 {
4057 throw new ArgumentOutOfRangeException ( "offset" , "Offset can't be negative." ) ;
@@ -43,7 +60,6 @@ private static void ThrowArgumentOutOfRangeExceptionForOffset()
4360 /// <summary>
4461 /// Throws an <see cref="ArgumentOutOfRangeException"/> when the input count is negative.
4562 /// </summary>
46- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
4763 private static void ThrowArgumentOutOfRangeExceptionForCount ( )
4864 {
4965 throw new ArgumentOutOfRangeException ( "count" , "Count can't be negative." ) ;
@@ -52,7 +68,6 @@ private static void ThrowArgumentOutOfRangeExceptionForCount()
5268 /// <summary>
5369 /// Throws an <see cref="ArgumentException"/> when the sum of offset and count exceeds the length of the target buffer.
5470 /// </summary>
55- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
5671 private static void ThrowArgumentExceptionForLength ( )
5772 {
5873 throw new ArgumentException ( "The sum of offset and count can't be larger than the buffer length." , "buffer" ) ;
@@ -61,47 +76,17 @@ private static void ThrowArgumentExceptionForLength()
6176 /// <summary>
6277 /// Throws a <see cref="NotSupportedException"/> when trying to write on a readonly stream.
6378 /// </summary>
64- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
6579 private static void ThrowNotSupportedExceptionForCanWrite ( )
6680 {
6781 throw new NotSupportedException ( "The current stream doesn't support writing." ) ;
6882 }
6983
70- /// <summary>
71- /// Throws an <see cref="ArgumentException"/> when trying to write too many bytes to the target stream.
72- /// </summary>
73- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
74- private static void ThrowArgumentExceptionForEndOfStreamOnWrite ( )
75- {
76- throw new ArgumentException ( "The current stream can't contain the requested input data." ) ;
77- }
78-
79- /// <summary>
80- /// Throws a <see cref="NotSupportedException"/> when trying to set the length of the stream.
81- /// </summary>
82- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
83- private static void ThrowNotSupportedExceptionForSetLength ( )
84- {
85- throw new NotSupportedException ( "Setting the length is not supported for this stream." ) ;
86- }
87-
88- /// <summary>
89- /// Throws an <see cref="ArgumentException"/> when using an invalid seek mode.
90- /// </summary>
91- /// <returns>Nothing, as this method throws unconditionally.</returns>
92- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
93- private static long ThrowArgumentExceptionForSeekOrigin ( )
94- {
95- throw new ArgumentException ( "The input seek mode is not valid." , "origin" ) ;
96- }
97-
9884 /// <summary>
9985 /// Throws an <see cref="ObjectDisposedException"/> when using a disposed <see cref="Stream"/> instance.
10086 /// </summary>
101- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
10287 private static void ThrowObjectDisposedException ( )
10388 {
104- throw new ObjectDisposedException ( nameof ( memory ) , "The current stream has already been disposed" ) ;
89+ throw new ObjectDisposedException ( "source" , "The current stream has already been disposed" ) ;
10590 }
10691 }
10792}
0 commit comments