本文整理汇总了C#中IronRuby.Runtime.BlockParam.Yield方法的典型用法代码示例。如果您正苦于以下问题:C# BlockParam.Yield方法的具体用法?C# BlockParam.Yield怎么用?C# BlockParam.Yield使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronRuby.Runtime.BlockParam
的用法示例。
在下文中一共展示了BlockParam.Yield方法的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: 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;
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: EachType
public static object EachType(RubyContext/*!*/ context, BlockParam/*!*/ block, TypeGroup/*!*/ self) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
foreach (Type type in self.Types) {
RubyModule module = context.GetModule(type);
object result;
if (block.Yield(module, out result)) {
return result;
}
}
return self;
}
示例7: Each
public static object Each(BlockParam block, RubyStruct/*!*/ self)
{
if (block == null && self.ItemCount > 0) {
throw RubyExceptions.NoBlockGiven();
}
foreach (var value in self.Values) {
object result;
if (block.Yield(value, out result)) {
return result;
}
}
return self;
}
示例8: EachPair
public static object EachPair(BlockParam block, RubyStruct/*!*/ self)
{
if (block == null && self.ItemCount > 0) {
throw RubyExceptions.NoBlockGiven();
}
var context = self.ImmediateClass.Context;
foreach (KeyValuePair<string, object> entry in self.GetItems()) {
object result;
if (block.Yield(context.EncodeIdentifier(entry.Key), entry.Value, out result)) {
return result;
}
}
return self;
}
示例9: Trap
public static object Trap(
RubyContext/*!*/ context,
BlockParam block,
object self,
object signalId) {
if ((signalId is MutableString) && ((MutableString)signalId).ConvertToString() == "INT") {
context.InterruptSignalHandler = delegate() { object result; block.Yield(out result); };
} else {
// TODO: For now, just ignore unknown signals. This should be changed to throw an
// exception. We are not doing it yet as it is close to the V1 RTM, and throwing
// an exception might cause some app to misbehave whereas it might have happenned
// to work if no exception is thrown
}
return null;
}
示例10: ChangeDirectory
public static object ChangeDirectory(BlockParam block, object/*!*/ self, MutableString dir) {
string strDir = dir.ConvertToString();
if (block == null) {
SetCurrentDirectory(strDir);
return 0;
} else {
string current = Directory.GetCurrentDirectory();
try {
SetCurrentDirectory(strDir);
object result;
block.Yield(dir, out result);
return result;
} finally {
SetCurrentDirectory(current);
}
}
}
示例11: TrueForItems
private static object TrueForItems(CallSiteStorage<EachSite>/*!*/ each, BlockParam predicate, object self, bool expected) {
bool result = expected;
Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
if (predicate != null) {
if (predicate.Yield(item, out item)) {
return item;
}
}
bool isTrue = Protocols.IsTrue(item);
if (isTrue != result) {
result = isTrue;
return selfBlock.Break(ScriptingRuntimeHelpers.BooleanToObject(isTrue));
}
return null;
}));
return ScriptingRuntimeHelpers.BooleanToObject(result);
}
示例12: DeleteIf
public static object DeleteIf(RubyContext/*!*/ context, BlockParam block, object/*!*/ self) {
PlatformAdaptationLayer pal = context.DomainManager.Platform;
IDictionary variables = pal.GetEnvironmentVariables();
if (variables.Count > 0 && block == null) {
throw RubyExceptions.NoBlockGiven();
}
foreach (DictionaryEntry entry in variables) {
MutableString key = MutableString.Create(entry.Key.ToString()).Freeze();
MutableString value = MutableString.Create(entry.Value.ToString()).Freeze();
object result;
if (block.Yield(key, value, out result)) {
return result;
}
if (RubyOps.IsTrue(result)) {
SetVariable(context, self, key, null);
}
}
return self;
}
示例13: EachObject
public static object EachObject(BlockParam block, RubyModule/*!*/ self, [NotNull]RubyClass/*!*/ theClass)
{
if (!theClass.HasAncestor(self.Context.ModuleClass)) {
throw RubyExceptions.CreateRuntimeError("each_object only supported for objects of type Class or Module");
}
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
int matches = 0;
List<RubyModule> visitedModules = new List<RubyModule>();
Stack<RubyModule> pendingModules = new Stack<RubyModule>();
pendingModules.Push(theClass.Context.ObjectClass);
while (pendingModules.Count > 0) {
RubyModule next = pendingModules.Pop();
visitedModules.Add(next);
if (theClass.Context.IsKindOf(next, theClass)) {
matches++;
object result;
if (block.Yield(next, out result)) {
return result;
}
}
using (theClass.Context.ClassHierarchyLocker()) {
next.EnumerateConstants(delegate(RubyModule module, string name, object value) {
RubyModule constAsModule = value as RubyModule;
if (constAsModule != null && !visitedModules.Contains(constAsModule)) {
pendingModules.Push(constAsModule);
}
return false;
});
}
}
return matches;
}
示例14: TrueForItems
private static object TrueForItems(CallSiteStorage<EachSite>/*!*/ each, BlockParam predicate, object self, bool stop, bool positiveResult) {
object result = ScriptingRuntimeHelpers.BooleanToObject(!positiveResult);
Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
if (predicate != null) {
object blockResult;
if (predicate.Yield(item, out blockResult)) {
result = blockResult;
return selfBlock.PropagateFlow(predicate, blockResult);
}
item = blockResult;
}
bool isTrue = Protocols.IsTrue(item);
if (isTrue == stop) {
result = ScriptingRuntimeHelpers.BooleanToObject(positiveResult);
return selfBlock.Break(result);
}
return null;
}));
return result;
}
示例15: GetProfile
public static object GetProfile(RubyContext/*!*/ context, BlockParam/*!*/ block, object self) {
if (!((RubyOptions)context.Options).Profile) {
throw RubyExceptions.CreateSystemCallError("You must enable profiling to use Clr.profile");
}
var start = Profiler.Instance.GetProfile();
object blockResult;
if (block.Yield(out blockResult)) {
return blockResult;
}
Hash result = new Hash(context);
foreach (var entry in Profiler.Instance.GetProfile()) {
long startTime;
if (!start.TryGetValue(entry.Key, out startTime)) {
startTime = 0;
}
long elapsed = entry.Value - startTime;
if (elapsed > 0) {
result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(elapsed));
}
}
return result;
}