本文整理汇总了C#中IronRuby.Runtime.BlockParam类的典型用法代码示例。如果您正苦于以下问题:C# BlockParam类的具体用法?C# BlockParam怎么用?C# BlockParam使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockParam类属于IronRuby.Runtime命名空间,在下文中一共展示了BlockParam类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EachObject
public static object EachObject(BlockParam block, RubyModule/*!*/ self, [NotNull]RubyClass/*!*/ theClass) {
Type classType = theClass.GetType();
bool isClass = (classType == typeof(RubyClass));
if (!isClass && classType != typeof(RubyModule)) {
throw new NotSupportedException("each_object only supported for objects of type Class or Module");
}
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
Dictionary<RubyModule, object> visited = new Dictionary<RubyModule, object>();
Stack<RubyModule> modules = new Stack<RubyModule>();
modules.Push(theClass.Context.ObjectClass);
while (modules.Count > 0) {
RubyModule next = modules.Pop();
RubyClass asClass = next as RubyClass;
if (!isClass || asClass != null) {
object result;
if (block.Yield(next, out result)) {
return result;
}
}
next.EnumerateConstants(delegate(RubyModule module, string name, object value) {
RubyModule constAsModule = (value as RubyModule);
if (constAsModule != null && !visited.ContainsKey(constAsModule)) {
modules.Push(constAsModule);
visited[module] = null;
}
return false;
});
}
return visited.Count;
}
示例2: CreateHash
public static Hash CreateHash(BlockParam block, RubyClass/*!*/ self, object defaultValue)
{
if (block != null) {
throw RubyExceptions.CreateArgumentError("wrong number of arguments");
}
return new Hash(self.Context.EqualityComparer, null, defaultValue);
}
示例3: Reinitialize
public static object Reinitialize(BlockParam block, RubyModule/*!*/ self) {
// no class can be reinitialized:
if (self.IsClass) {
throw RubyExceptions.CreateTypeError("already initialized class");
}
return (block != null) ? RubyUtils.EvaluateInModule(self, block, null) : null;
}
示例4: BlockRetry
public static object BlockRetry(BlockParam/*!*/ blockFlowControl) {
if (blockFlowControl.CallerKind == BlockCallerKind.Yield) {
blockFlowControl.SetFlowControl(BlockReturnReason.Retry, null, blockFlowControl.Proc.Kind);
return RetrySingleton;
} else {
throw new LocalJumpError("retry from proc-closure");
}
}
示例5: Initialize
public static Hash/*!*/ Initialize(BlockParam block, Hash/*!*/ self, object defaultValue) {
Assert.NotNull(self);
if (block != null) {
throw RubyExceptions.CreateArgumentError("wrong number of arguments");
}
self.DefaultProc = null;
self.DefaultValue = defaultValue;
return self;
}
示例6: Create
/// <summary>
/// Struct#new
/// Creates Struct classes with the specified name and members
/// </summary>
private static object Create(BlockParam block, RubyClass/*!*/ self, string className, string/*!*/[]/*!*/ attributeNames) {
var result = RubyStruct.DefineStruct(self, className, attributeNames);
if (block != null) {
return RubyUtils.EvaluateInModule(result, block, null, result);
}
return result;
}
示例7: AtExit
public static Proc AtExit(BlockParam/*!*/ block, object self)
{
if (block == null) {
throw RubyExceptions.CreateArgumentError("called without a block");
}
block.RubyContext.RegisterShutdownHandler(block.Proc);
return block.Proc;
}
示例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: NewStruct
public static object NewStruct(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol]MutableString className,
[DefaultProtocol, NotNullItems]params string/*!*/[]/*!*/ attributeNames) {
if (className == null) {
return Create(block, self, null, attributeNames);
}
string strName = className.ConvertToString();
RubyUtils.CheckConstantName(strName);
return Create(block, self, strName, attributeNames);
}
示例10: Synchronize
public static object Synchronize(BlockParam criticalSection, RubyMutex/*!*/ self) {
lock (self._mutex) {
self._isLocked = true;
try {
object result;
criticalSection.Yield(out result);
return result;
} finally {
self._isLocked = false;
}
}
}
示例11: NewStruct
public static object NewStruct(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, Optional]MutableString className,
[NotNull]params object[]/*!*/ attributeNames) {
string[] symbols = Protocols.CastToSymbols(self.Context, attributeNames);
if (className == null) {
return Create(block, self, null, symbols);
}
string strName = className.ConvertToString();
RubyUtils.CheckConstantName(strName);
return Create(block, self, strName, symbols);
}
示例12: Map
public static RubyArray Map(RubyContext/*!*/ context, BlockParam collector, object self) {
RubyArray result = new RubyArray();
Each(context, self, Proc.Create(context, delegate(BlockParam/*!*/ selfBlock, object item) {
if (collector != null) {
if (collector.Yield(item, out item)) {
return item;
}
}
result.Add(item);
return null;
}));
return result;
}
示例13: Each
public static object Each(BlockParam block, IEnumerable/*!*/ self) {
foreach (object obj in self) {
object result;
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
if (block.Yield(obj, out result)) {
return result;
}
}
return self;
}
示例14: Map
public static RubyArray Map(CallSiteStorage<EachSite>/*!*/ each, BlockParam collector, object self) {
RubyArray result = new RubyArray();
Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
if (collector != null) {
if (collector.Yield(item, out item)) {
return item;
}
}
result.Add(item);
return null;
}));
return result;
}
示例15: 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;
}