public static MutableString/*!*/ Read(
ConversionStorage<IDictionary<object, object>>/*!*/ toHash,
ConversionStorage<int>/*!*/ fixnumCast,
ConversionStorage<MutableString>/*!*/ toPath,
RubyClass/*!*/ self,
object path,
[Optional]object optionsOrLength,
[Optional]object optionsOrOffset,
[DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options) {
Protocols.TryConvertToOptions(toHash, ref options, ref optionsOrLength, ref optionsOrOffset);
var site = fixnumCast.GetSite(ConvertToFixnumAction.Make(fixnumCast.Context));
int length = (optionsOrLength != Missing.Value && optionsOrLength != null) ? site.Target(site, optionsOrLength) : 0;
int offset = (optionsOrOffset != Missing.Value && optionsOrOffset != null) ? site.Target(site, optionsOrOffset) : 0;
if (offset < 0) {
throw RubyExceptions.CreateEINVAL();
}
if (length < 0) {
throw RubyExceptions.CreateArgumentError("negative length {0} given", length);
}
// TODO: options
using (RubyIO io = new RubyFile(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path)), IOMode.ReadOnly)) {
if (offset > 0) {
io.Seek(offset, SeekOrigin.Begin);
}
if (optionsOrLength != Missing.Value && optionsOrLength != null) {
return Read(io, length, null);
} else {
return Read(io);
}
}
}