Preface
For some time now I've been using the readonly modifier for nearly all class fields. I use it for List<T> members, IDisposeable members, ints, strings, etc... everything but value types I intend to change. I tend to do this even when I would normally like to null a member on Dispose(). IMHO The advantages of not needing the if statements to test for null or disposed conditions greatly outweigh the 'potential' for trouble in objects that 'could' be disposed multiple times.
The Question
When do you use readonly, or do you?
Do you or your company have any best-practices and/or coding standards regarding the use of readonly?
I'm curious to hear your thoughts on the following sample class, is the general concept a good practice or not?
class FileReaderWriter : IFileReaderWriter, IDisposable
{
private readonly string _file;
private readonly Stream _io;
public FileReaderWriter(string path)
{
_io = File.Open(_file = Check.NotEmpty(path), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}
public void Dispose() { _io.Dispose(); }
...
}