本文整理汇总了C#中Iterator.valid方法的典型用法代码示例。如果您正苦于以下问题:C# Iterator.valid方法的具体用法?C# Iterator.valid怎么用?C# Iterator.valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Iterator
的用法示例。
在下文中一共展示了Iterator.valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PhpArray
public static PhpArray/*!*/ToArray(ScriptContext/*!*/context, Iterator/*!*/iterator, bool use_keys/*=true*/)
{
// check parameters:
Debug.Assert(context != null);
Debug.Assert(iterator != null, "Phalanger should not pass a null here.");
//
var array = new PhpArray();
// iterate through the iterator:
iterator.rewind(context);
while (PHP.Core.Convert.ObjectToBoolean(iterator.valid(context)))
{
object value = iterator.current(context); // PHP calls current() first
if (use_keys)
array[iterator.key(context)] = value;
else
array.Add(value);
iterator.next(context);
}
// return amount of iterated elements:
return array;
}
示例2: Apply
public static int Apply(ScriptContext/*!*/context, PHP.Core.Reflection.DTypeDesc caller, Iterator/*!*/iterator, PhpCallback function, PhpArray args)
{
// check parameters:
Debug.Assert(context != null);
Debug.Assert(iterator != null, "Phalanger should not pass a null here.");
if (function == null)
{
PhpException.ArgumentNull("function");
return -1;
}
// copy args into object array:
object[] args_array;
if (args != null)
{
args_array = new object[args.Count];
args.Values.CopyTo(args_array, 0);
}
else
{
args_array = ArrayUtils.EmptyObjects;
}
// iterate through the iterator:
int n = 0;
iterator.rewind(context);
while (PHP.Core.Convert.ObjectToBoolean(iterator.valid(context)))
{
if (!PHP.Core.Convert.ObjectToBoolean(function.Invoke(caller, args_array)))
break;
n++;
iterator.next(context);
}
// return amount of iterated elements:
return n;
}
示例3: Count
public static int Count(ScriptContext/*!*/context, Iterator/*!*/iterator)
{
// check parameters:
Debug.Assert(context != null);
Debug.Assert(iterator != null, "Phalanger should not pass a null here.");
// iterate through the iterator:
int n = 0;
iterator.rewind(context);
while (PHP.Core.Convert.ObjectToBoolean(iterator.valid(context)))
{
n++;
iterator.next(context);
}
// return amount of iterated elements:
return n;
}