当前位置: 首页>>代码示例>>C#>>正文


C# Runtime.BlockParam类代码示例

本文整理汇总了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;
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:34,代码来源:ObjectSpace.cs

示例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);
 }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:HashOps.cs

示例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;
        }
开发者ID:atczyc,项目名称:ironruby,代码行数:8,代码来源:ModuleOps.cs

示例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");
     }
 }
开发者ID:andreakn,项目名称:ironruby,代码行数:8,代码来源:RubyOps.FlowControl.cs

示例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;
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:9,代码来源:HashOps.cs

示例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;
        }
开发者ID:jschementi,项目名称:iron,代码行数:13,代码来源:StructOps.cs

示例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;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:9,代码来源:KernelOps.cs

示例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);
 }
开发者ID:nrk,项目名称:ironruby-hpricot,代码行数:10,代码来源:Hpricot.cs

示例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);
        }
开发者ID:jschementi,项目名称:iron,代码行数:11,代码来源:StructOps.cs

示例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;
         }
     }
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:12,代码来源:RubyMutex.cs

示例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);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:13,代码来源:StructOps.cs

示例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;
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:13,代码来源:Enumerable.cs

示例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;
        }
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:13,代码来源:IEnumerableOps.cs

示例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;
 }
开发者ID:Hank923,项目名称:ironruby,代码行数:13,代码来源:Enumerable.cs

示例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;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:15,代码来源:Enumerable.cs


注:本文中的IronRuby.Runtime.BlockParam类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。