本文整理汇总了C#中BinaryOpStorage类的典型用法代码示例。如果您正苦于以下问题:C# BinaryOpStorage类的具体用法?C# BinaryOpStorage怎么用?C# BinaryOpStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryOpStorage类属于命名空间,在下文中一共展示了BinaryOpStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(BinaryOpStorage/*!*/ comparisonStorage,
RubyContext/*!*/ context, object begin, object end, bool excludeEnd) {
if (_initialized) {
throw RubyExceptions.CreateNameError("`initialize' called twice");
}
// Range tests whether the items can be compared, and uses that to determine if the range is valid
// Only a non-existent <=> method or a result of nil seems to trigger the exception.
object compareResult;
var site = comparisonStorage.GetCallSite("<=>");
try {
compareResult = site.Target(site, begin, end);
} catch (Exception) {
compareResult = null;
}
if (compareResult == null) {
throw RubyExceptions.CreateArgumentError("bad value for range");
}
_begin = begin;
_end = end;
_excludeEnd = excludeEnd;
_initialized = true;
}
示例2: Abort
public static void Abort(BinaryOpStorage/*!*/ writeStorage, object/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ message)
{
var site = writeStorage.GetCallSite("write", 1);
site.Target(site, writeStorage.Context.StandardErrorOutput, message);
Exit(self, 1);
}
示例3: Equal
public static bool Equal(BinaryOpStorage/*!*/ equals, decimal self, object other) {
if (other is decimal) {
return self == (decimal)other;
}
// Call == on the right operand like Float#== does
return Protocols.IsEqual(equals, other, self);
}
示例4: PrintFormatted
public static void PrintFormatted(
StringFormatterSiteStorage/*!*/ storage,
ConversionStorage<MutableString>/*!*/ stringCast,
BinaryOpStorage/*!*/ writeStorage,
object/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format, params object[]/*!*/ args)
{
KernelOps.PrintFormatted(storage, stringCast, writeStorage, null, self, format, args);
}
示例5: Print
public static void Print(BinaryOpStorage/*!*/ writeStorage, object self, object value) {
Protocols.Write(writeStorage, self, value ?? MutableString.CreateAscii("nil"));
MutableString delimiter = writeStorage.Context.OutputSeparator;
if (delimiter != null) {
Protocols.Write(writeStorage, self, delimiter);
}
}
示例6: Abs
public static object Abs(BinaryOpStorage/*!*/ lessThanStorage, UnaryOpStorage/*!*/ minusStorage, object self)
{
var lessThan = lessThanStorage.GetCallSite("<");
if (RubyOps.IsTrue(lessThan.Target(lessThan, self, 0))) {
var minus = minusStorage.GetCallSite("[email protected]");
return minus.Target(minus, self);
}
return self;
}
示例7: ToYamlProperties
public static RubyArray/*!*/ ToYamlProperties(
BinaryOpStorage/*!*/ comparisonStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
RubyContext/*!*/ context, object self) {
return ArrayOps.SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, context,
null, KernelOps.InstanceVariables(context, self)
);
}
示例8: Scan
public static Object Scan(ConversionStorage<MutableString>/*!*/ toMutableStringStorage, RespondToStorage/*!*/ respondsTo,
BinaryOpStorage/*!*/ readIOStorage, BlockParam block, RubyModule/*!*/ self, Object/*!*/ source, Hash/*!*/ options)
{
Object elementContent;
if (!self.TryGetConstant(null, "ElementContent", out elementContent) && !(elementContent is Hash)) {
throw new Exception("Hpricot::ElementContent is missing or it is not an Hash");
}
var scanner = new HpricotScanner(toMutableStringStorage, readIOStorage, block);
return scanner.Scan(source, options, elementContent as Hash);
}
示例9: Putc
public static MutableString/*!*/ Putc(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ val) {
if (val.IsEmpty) {
throw RubyExceptions.CreateTypeError("can't convert String into Integer");
}
// writes a single byte into the output stream:
var c = MutableString.CreateBinary(val.GetBinarySlice(0, 1));
Protocols.Write(writeStorage, self, c);
return val;
}
示例10: DefineFinalizer
public static object DefineFinalizer(RespondToStorage/*!*/ respondTo, BinaryOpStorage/*!*/ call, RubyModule/*!*/ self, object obj, object finalizer)
{
if (!Protocols.RespondTo(respondTo, finalizer, "call")) {
throw RubyExceptions.CreateArgumentError("finalizer should be callable (respond to :call)");
}
respondTo.Context.SetInstanceVariable(obj, FinalizerInvoker.InstanceVariableName, new FinalizerInvoker(call.GetCallSite("call"), finalizer));
RubyArray result = new RubyArray(2);
result.Add(0);
result.Add(finalizer);
return result;
}
示例11: Contains
public static object Contains(CallSiteStorage<EachSite>/*!*/ each, BinaryOpStorage/*!*/ equals, object self, object value)
{
object result = ScriptingRuntimeHelpers.BooleanToObject(false);
Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
if (Protocols.IsEqual(equals, item, value)) {
result = ScriptingRuntimeHelpers.BooleanToObject(true);
return selfBlock.Break(result);
}
return null;
}));
return result;
}
示例12: Count
public static int Count(CallSiteStorage<EachSite>/*!*/ each, BinaryOpStorage/*!*/ equals, BlockParam comparer, object self, object value)
{
if (comparer != null) {
each.Context.ReportWarning("given block not used");
}
int result = 0;
Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
if (Protocols.IsEqual(equals, item, value)) {
result++;
}
return null;
}));
return result;
}
示例13: Equal
public static bool Equal(BinaryOpStorage/*!*/ compareStorage, object self, object other)
{
if (self == other) {
return true;
}
// calls method_missing:
var compare = compareStorage.GetCallSite("<=>");
object compareResult;
try {
compareResult = compare.Target(compare, self, other);
} catch (SystemException) {
// catches StandardError (like rescue)
return false;
}
return compareResult is int && (int)compareResult == 0;
}
示例14: SysWrite
public static int SysWrite(BinaryOpStorage/*!*/ writeStorage, ConversionStorage<MutableString>/*!*/ tosConversion,
RubyContext/*!*/ context, RubyIO/*!*/ self, object obj) {
return SysWrite(writeStorage, tosConversion, context, self, Protocols.ConvertToString(tosConversion, obj));
}
示例15: CopyStream
public static object CopyStream(
ConversionStorage<MutableString>/*!*/ toPath, ConversionStorage<int>/*!*/ toInt, RespondToStorage/*!*/ respondTo,
BinaryOpStorage/*!*/ writeStorage, CallSiteStorage<Func<CallSite, object, object, object, object>>/*!*/ readStorage,
RubyClass/*!*/ self, object src, object dst, [DefaultParameterValue(-1)]int count, [DefaultParameterValue(-1)]int src_offset) {
if (count < -1) {
throw RubyExceptions.CreateArgumentError("count should be >= -1");
}
if (src_offset < -1) {
throw RubyExceptions.CreateArgumentError("src_offset should be >= -1");
}
RubyIO srcIO = src as RubyIO;
RubyIO dstIO = dst as RubyIO;
Stream srcStream = null, dstStream = null;
var context = toPath.Context;
CallSite<Func<CallSite, object, object, object>> writeSite = null;
CallSite<Func<CallSite, object, object, object, object>> readSite = null;
try {
if (srcIO == null || dstIO == null) {
var toPathSite = toPath.GetSite(TryConvertToPathAction.Make(toPath.Context));
var srcPath = toPathSite.Target(toPathSite, src);
if (srcPath != null) {
srcStream = new FileStream(context.DecodePath(srcPath), FileMode.Open, FileAccess.Read);
} else {
readSite = readStorage.GetCallSite("read", 2);
}
var dstPath = toPathSite.Target(toPathSite, dst);
if (dstPath != null) {
dstStream = new FileStream(context.DecodePath(dstPath), FileMode.Truncate);
} else {
writeSite = writeStorage.GetCallSite("write", 1);
}
} else {
srcStream = srcIO.GetReadableStream();
dstStream = dstIO.GetWritableStream();
}
if (src_offset != -1) {
if (srcStream == null) {
throw RubyExceptions.CreateArgumentError("cannot specify src_offset for non-IO");
}
srcStream.Seek(src_offset, SeekOrigin.Current);
}
MutableString userBuffer = null;
byte[] buffer = null;
long bytesCopied = 0;
long remaining = (count < 0) ? Int64.MaxValue : count;
int minBufferSize = 16 * 1024;
if (srcStream != null) {
buffer = new byte[Math.Min(minBufferSize, remaining)];
}
while (remaining > 0) {
int bytesRead;
int chunkSize = (int)Math.Min(minBufferSize, remaining);
if (srcStream != null) {
userBuffer = null;
bytesRead = srcStream.Read(buffer, 0, chunkSize);
} else {
userBuffer = MutableString.CreateBinary();
bytesRead = Protocols.CastToFixnum(toInt, readSite.Target(readSite, src, chunkSize, userBuffer));
}
if (bytesRead <= 0) {
break;
}
if (dstStream != null) {
if (userBuffer != null) {
dstStream.Write(userBuffer, 0, bytesRead);
} else {
dstStream.Write(buffer, 0, bytesRead);
}
} else {
if (userBuffer == null) {
userBuffer = MutableString.CreateBinary(bytesRead).Append(buffer, 0, bytesRead);
} else {
userBuffer.SetByteCount(bytesRead);
}
writeSite.Target(writeSite, dst, userBuffer);
}
bytesCopied += bytesRead;
remaining -= bytesRead;
}
return Protocols.Normalize(bytesCopied);
} finally {
if (srcStream != null) {
srcStream.Close();
}
if (dstStream != null) {
dstStream.Close();
}
//.........这里部分代码省略.........