Can one extend the type itself and not just an instance of the type?
So I have something, say, like
public static DateTime RawRead(this DateTime i, Stream s)
{
BinaryReader b = new BinaryReader(s);
i = DateTime.FromBinary(b.ReadInt64());
return i;
}
But how I have to use it is
DateTime d = new DateTime();
d = d.RawRead(s);
I'd like to be able to do
DateTime d = DateTime.RawRead(s);
or even
DateTime d = new DateTime();
d.RawRead(s);
In a sense I need something like
public static DateTime RawRead(this ref DateTime i, Stream s)
{
BinaryReader b = new BinaryReader(s);
i = DateTime.FromBinary(b.ReadInt64());
}
But of course that doesn't work. (Or even a way to extend the type itself)
Ultimately its not that big a deal but its a little messy to have to use the
instance itself to call the method. (and for the fact that it creates two
objects since I first have to instantiate it then return a new one)
Thanks,
Jon