Reputation: 1806
Is there some wrapper in .NET for file bytes?
I don't like working with byte[]. The type (byte[]) doesn't give enough semantic meaning in case of file bytes because not all byte[] are file bytes. Also passing it as an argument is discomforting...
I know it would be easy to write that kind of wrapper of my own. e.g.:
public class FileBytes
{
public FileBytes
(
byte[] value
)
{
Contract.Requires(value != null);
Contract.Requires(value.Length != 0);
this.Value = value;
}
public byte[] Value { get; private set; }
}
But I wonder is there's some out of .NET-box solution.
Upvotes: 2
Views: 178
Reputation: 171178
There is no such thing in the BCL. (Or maybe the Stream
abstraction is what you are looking for?)
Your wrapper has the same problem that a raw byte[]
has in that variables of type FileBytes
can be null
.
Also, I don't see why bytes coming from a file would be any different than bytes coming from somewhere else (e.g. from the web). Code operating on bytes should act the same way no matter where they came from.
Upvotes: 8