11using System . Buffers ;
22using System . IO . MemoryMappedFiles ;
3- #if NET
43using System . Runtime . Versioning ;
5- #endif
64using Microsoft . Extensions . Logging ;
75using Microsoft . Extensions . Options ;
86using TinyIpc . Synchronization ;
@@ -34,9 +32,7 @@ public partial class TinyMemoryMappedFile : ITinyMemoryMappedFile
3432 /// Initializes a new instance of the TinyMemoryMappedFile class.
3533 /// </summary>
3634 /// <param name="options">Options from dependency injection or an OptionsWrapper containing options</param>
37- #if NET
3835 [ SupportedOSPlatform ( "windows" ) ]
39- #endif
4036 public TinyMemoryMappedFile ( ITinyReadWriteLock readWriteLock , IOptions < TinyIpcOptions > options , ILogger < TinyMemoryMappedFile > logger )
4137 : this ( ( options ?? throw new ArgumentNullException ( nameof ( options ) ) ) . Value . Name , options . Value . MaxFileSize , readWriteLock , disposeLock : false , logger )
4238 {
@@ -46,9 +42,7 @@ public TinyMemoryMappedFile(ITinyReadWriteLock readWriteLock, IOptions<TinyIpcOp
4642 /// Initializes a new instance of the TinyMemoryMappedFile class.
4743 /// </summary>
4844 /// <param name="name">A system wide unique name, the name will have a prefix appended before use</param>
49- #if NET
5045 [ SupportedOSPlatform ( "windows" ) ]
51- #endif
5246 public TinyMemoryMappedFile ( string name , ILogger < TinyMemoryMappedFile > ? logger = null )
5347 : this ( name , TinyIpcOptions . DefaultMaxFileSize , logger )
5448 {
@@ -59,9 +53,7 @@ public TinyMemoryMappedFile(string name, ILogger<TinyMemoryMappedFile>? logger =
5953 /// </summary>
6054 /// <param name="name">A system wide unique name, the name will have a prefix appended before use</param>
6155 /// <param name="maxFileSize">The maximum amount of data that can be written to the file memory mapped file</param>
62- #if NET
6356 [ SupportedOSPlatform ( "windows" ) ]
64- #endif
6557 public TinyMemoryMappedFile ( string name , long maxFileSize , ILogger < TinyMemoryMappedFile > ? logger = null )
6658 : this ( name , maxFileSize , new TinyReadWriteLock ( name ) , disposeLock : true , logger )
6759 {
@@ -74,9 +66,7 @@ public TinyMemoryMappedFile(string name, long maxFileSize, ILogger<TinyMemoryMap
7466 /// <param name="maxFileSize">The maximum amount of data that can be written to the file memory mapped file</param>
7567 /// <param name="readWriteLock">A read/write lock that will be used to control access to the memory mapped file</param>
7668 /// <param name="disposeLock">Set to true if the read/write lock is to be disposed when this instance is disposed</param>
77- #if NET
7869 [ SupportedOSPlatform ( "windows" ) ]
79- #endif
8070 public TinyMemoryMappedFile ( string name , long maxFileSize , ITinyReadWriteLock readWriteLock , bool disposeLock , ILogger < TinyMemoryMappedFile > ? logger = null )
8171 : this ( CreateOrOpenMemoryMappedFile ( name , maxFileSize ) , CreateEventWaitHandle ( name ) , maxFileSize , readWriteLock , disposeLock , logger )
8272 {
@@ -151,14 +141,7 @@ protected virtual void Dispose(bool disposing)
151141 /// <returns>File size</returns>
152142 public int GetFileSize ( CancellationToken cancellationToken = default )
153143 {
154- #if NET
155144 ObjectDisposedException . ThrowIf ( disposed , this ) ;
156- #else
157- if ( disposed )
158- {
159- throw new ObjectDisposedException ( nameof ( TinyMemoryMappedFile ) ) ;
160- }
161- #endif
162145
163146 using var readLock = readWriteLock . AcquireReadLock ( cancellationToken ) ;
164147 using var accessor = memoryMappedFile . CreateViewAccessor ( ) ;
@@ -178,23 +161,8 @@ public int GetFileSize(CancellationToken cancellationToken = default)
178161 /// <returns>File content</returns>
179162 public T Read < T > ( Func < MemoryStream , T > readData , CancellationToken cancellationToken = default )
180163 {
181- #if NET
182164 ArgumentNullException . ThrowIfNull ( readData ) ;
183- #else
184- if ( readData is null )
185- {
186- throw new ArgumentNullException ( nameof ( readData ) ) ;
187- }
188- #endif
189-
190- #if NET
191165 ObjectDisposedException . ThrowIf ( disposed , this ) ;
192- #else
193- if ( disposed )
194- {
195- throw new ObjectDisposedException ( nameof ( TinyMemoryMappedFile ) ) ;
196- }
197- #endif
198166
199167 using var readLock = readWriteLock . AcquireReadLock ( cancellationToken ) ;
200168 using var readStream = MemoryStreamPool . Manager . GetStream ( nameof ( TinyMemoryMappedFile ) ) ;
@@ -215,14 +183,7 @@ public T Read<T>(Func<MemoryStream, T> readData, CancellationToken cancellationT
215183 /// </summary>
216184 public void Write ( MemoryStream data , CancellationToken cancellationToken = default )
217185 {
218- #if NET
219186 ArgumentNullException . ThrowIfNull ( data ) ;
220- #else
221- if ( data is null )
222- {
223- throw new ArgumentNullException ( nameof ( data ) ) ;
224- }
225- #endif
226187
227188#if NET
228189 ArgumentOutOfRangeException . ThrowIfGreaterThan ( data . Length , MaxFileSize ) ;
@@ -233,14 +194,7 @@ public void Write(MemoryStream data, CancellationToken cancellationToken = defau
233194 }
234195#endif
235196
236- #if NET
237197 ObjectDisposedException . ThrowIf ( disposed , this ) ;
238- #else
239- if ( disposed )
240- {
241- throw new ObjectDisposedException ( nameof ( TinyMemoryMappedFile ) ) ;
242- }
243- #endif
244198
245199 // Make sure the file watcher is ready before writing
246200 watcherTaskCompletionSource . Task . GetAwaiter ( ) . GetResult ( ) ;
@@ -268,23 +222,8 @@ public void Write(MemoryStream data, CancellationToken cancellationToken = defau
268222 /// </summary>
269223 public void ReadWrite ( Action < MemoryStream , MemoryStream > updateFunc , CancellationToken cancellationToken = default )
270224 {
271- #if NET
272225 ArgumentNullException . ThrowIfNull ( updateFunc ) ;
273- #else
274- if ( updateFunc is null )
275- {
276- throw new ArgumentNullException ( nameof ( updateFunc ) ) ;
277- }
278- #endif
279-
280- #if NET
281226 ObjectDisposedException . ThrowIf ( disposed , this ) ;
282- #else
283- if ( disposed )
284- {
285- throw new ObjectDisposedException ( nameof ( TinyMemoryMappedFile ) ) ;
286- }
287- #endif
288227
289228 // Make sure the file watcher is ready before writing
290229 watcherTaskCompletionSource . Task . GetAwaiter ( ) . GetResult ( ) ;
@@ -400,9 +339,7 @@ private void InternalWrite(MemoryStream input)
400339 /// <param name="name">A system wide unique name, the name will have a prefix appended</param>
401340 /// <param name="maxFileSize">The maximum amount of data that can be written to the file memory mapped file</param>
402341 /// <returns>A system wide MemoryMappedFile</returns>
403- #if NET
404342 [ SupportedOSPlatform ( "windows" ) ]
405- #endif
406343 public static MemoryMappedFile CreateOrOpenMemoryMappedFile ( string name , long maxFileSize )
407344 {
408345 if ( string . IsNullOrWhiteSpace ( name ) )
0 commit comments