Skip to content

Commit

Permalink
feat: Add an explicit cast operator for FileSystemStream (#940)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Birnsen committed Jan 31, 2023
1 parent 473e320 commit 70cea5d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/TestableIO.System.IO.Abstractions/FileSystemStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,15 @@ protected override void Dispose(bool disposing)
_stream.Dispose();
base.Dispose(disposing);
}

/// <summary>
/// Allows to cast the internal Stream to a FileStream
/// </summary>
/// <param name="fsStream">The FileSystemStream to cast</param>
/// <exception cref="InvalidCastException"></exception>
public static explicit operator FileStream(FileSystemStream fsStream)
{
return (FileStream) fsStream._stream;
}
}
}

0 comments on commit 70cea5d

Please sign in to comment.