Skip to content

Commit 70cea5d

Browse files
authored
feat: Add an explicit cast operator for FileSystemStream (#940)
This commit adds an explicit cast to change the fact, that the underlaying FileStream can not be accessed in any way. This has also the advantage that if the library is updated no code change is necessary if a cast was present from a stream.
1 parent 473e320 commit 70cea5d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/TestableIO.System.IO.Abstractions/FileSystemStream.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,15 @@ protected override void Dispose(bool disposing)
204204
_stream.Dispose();
205205
base.Dispose(disposing);
206206
}
207+
208+
/// <summary>
209+
/// Allows to cast the internal Stream to a FileStream
210+
/// </summary>
211+
/// <param name="fsStream">The FileSystemStream to cast</param>
212+
/// <exception cref="InvalidCastException"></exception>
213+
public static explicit operator FileStream(FileSystemStream fsStream)
214+
{
215+
return (FileStream) fsStream._stream;
216+
}
207217
}
208218
}

0 commit comments

Comments
 (0)