本文整理汇总了C#中System.Collections.IEnumerator.MoveNext方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.IEnumerator.MoveNext方法的具体用法?C# System.Collections.IEnumerator.MoveNext怎么用?C# System.Collections.IEnumerator.MoveNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.IEnumerator
的用法示例。
在下文中一共展示了System.Collections.IEnumerator.MoveNext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RestCollection
internal RestCollection(IEnumerator enumerator)
{
if (enumerator == null)
this._inner = new object[0];
else
{
ArrayList list = new ArrayList();
//try
//{
// object o = enumerator.Current;
// list.Add(o);
//}
//catch (InvalidOperationException)
//{
// // Just means there's no current object
//}
while (enumerator.MoveNext())
{
list.Add(enumerator.Current);
}
this._inner = list;
_count = _inner.Count-1;
}
}
示例2: Next
public override bool Next()
{
if (termEnum == null)
return false;
// another term in this field?
if (termEnum.Next() && (System.Object) termEnum.Term().Field() == (System.Object) field)
return true; // yes, keep going
termEnum.Close(); // close old termEnum
// find the next field with terms, if any
if (fieldIterator == null)
{
System.Collections.Comparer comparer = System.Collections.Comparer.Default;
System.Collections.SortedList newList = new System.Collections.SortedList();
if (Enclosing_Instance.fieldToReader != null)
{
if (Enclosing_Instance.fieldToReader.Count > 0)
{
int index = 0;
while (comparer.Compare(Enclosing_Instance.fieldToReader.GetKey(index), field) < 0)
index++;
for (; index < Enclosing_Instance.fieldToReader.Count; index++)
{
newList.Add(Enclosing_Instance.fieldToReader.GetKey(index), Enclosing_Instance.fieldToReader[Enclosing_Instance.fieldToReader.GetKey(index)]);
}
}
}
fieldIterator = newList.Keys.GetEnumerator();
fieldIterator.MoveNext();
System.Object generatedAux = fieldIterator.Current; // Skip field to get next one
}
while (fieldIterator.MoveNext())
{
field = ((System.String) fieldIterator.Current);
termEnum = ((IndexReader) Enclosing_Instance.fieldToReader[field]).Terms(new Term(field));
Term term = termEnum.Term();
if (term != null && (System.Object) term.Field() == (System.Object) field)
return true;
else
termEnum.Close();
}
return false; // no more fields
}
示例3: IsEmptyEnumerator
/// <summary>
/// Tests whether an IEnumerator is "empty", leaving IEnumerator at same position
/// </summary>
/// <param name="enumerator">IEnumerator instance to test</param>
/// <returns>True if enumerator is empty, false otherwise</returns>
public static bool IsEmptyEnumerator(IEnumerator enumerator)
{
try
{
object o = enumerator.Current;
return false;
}
catch (InvalidOperationException)
{
// We are either at the start of a collection or, lumbered with an invalid enumerator
try
{
if (enumerator.MoveNext())
{
// put it back to start of list
enumerator.Reset();
return false;
}
}
catch (InvalidOperationException)
{
// lumbered with a dead duck
}
}
return true;
}
示例4: RotateMapIterator
protected virtual List<Template> RotateMapIterator(TemplateFrame frame, IEnumerator iterator, List<Template> prototypes)
{
List<Template> mapped = new List<Template>();
int i0 = 0;
int i = 1;
int ti = 0;
while (iterator.MoveNext())
{
object iterValue = iterator.Current;
if (iterValue == null)
{
mapped.Add(null);
continue;
}
int templateIndex = ti % prototypes.Count; // rotate through
ti++;
Template proto = prototypes[templateIndex];
Template st = group.CreateStringTemplateInternally(proto);
SetFirstArgument(frame, st, iterValue);
if (st.impl.IsAnonSubtemplate)
{
st.RawSetAttribute("i0", i0);
st.RawSetAttribute("i", i);
}
mapped.Add(st);
i0++;
i++;
}
return mapped;
}
示例5: Next
public override bool Next()
{
if (termEnum == null)
return false;
// another term in this field?
if (termEnum.Next() && (System.Object) termEnum.Term().Field() == (System.Object) field)
return true; // yes, keep going
termEnum.Close(); // close old termEnum
// find the next field with terms, if any
if (fieldIterator == null)
{
fieldIterator = SupportClass.TailMap(Enclosing_Instance.fieldToReader, field).Keys.GetEnumerator();
fieldIterator.MoveNext(); // Skip field to get next one
}
while (fieldIterator.MoveNext())
{
field = ((System.String) fieldIterator.Current);
termEnum = ((IndexReader) Enclosing_Instance.fieldToReader[field]).Terms(new Term(field, ""));
Term term = termEnum.Term();
if (term != null && (System.Object) term.Field() == (System.Object) field)
return true;
else
termEnum.Close();
}
return false; // no more fields
}
示例6: Iterator
public Iterator( IEnumerable enumerable )
{
_enumerable = enumerable;
_iterator = enumerable.GetEnumerator();
_hasNext = _iterator.MoveNext();
}
示例7: WriteIterableValue
protected virtual int WriteIterableValue(StringTemplate self, IEnumerator iter, IStringTemplateWriter @out)
{
int n = 0;
bool seenAValue = false;
while (iter.MoveNext())
{
object iterValue = iter.Current ?? _nullValue;
if (iterValue != null)
{
// if no separator or separator but iterValue isn't a single IF condition template
if (_separatorString == null)
{
// if no separator, don't waste time writing to temp buffer
int nw = Write(self, iterValue, @out);
if (nw != Missing)
n += nw;
continue;
}
/* if value to emit is a template, only buffer its
* value if it's nullable (can eval to missing).
* Only a sequence of IF can eval to missing.
*/
StringTemplate st = iterValue as StringTemplate;
if (st != null)
{
int nchunks = st.Chunks != null ? st.Chunks.Count : 0;
bool nullable = true;
for (int i = 0; i < nchunks; i++)
{
Expr a = st.Chunks[i];
if (!(a is ConditionalExpr))
nullable = false;
}
// if not all IF, not nullable, spit out w/o buffering
if (!nullable)
{
if (seenAValue && _separatorString != null)
{
n += @out.WriteSeparator(_separatorString);
}
int nw = Write(self, iterValue, @out);
n += nw;
seenAValue = true;
continue;
}
}
else if (!(iterValue is IEnumerator))
{
// if not possible to be missing, don't waste time
// writing to temp buffer; might need separator though
if (seenAValue && _separatorString != null)
{
n += @out.WriteSeparator(_separatorString);
}
int nw = Write(self, iterValue, @out);
seenAValue = true;
n += nw;
continue;
}
/* if separator exists, write iterated value to a
* tmp buffer in case we don't need a separator.
* Can't generate separator then test next expr value
* as we can't undo separator emit.
* Write to dummy buffer to if it is MISSING
* but eval/write value again to real out so
* we get proper autowrap etc...
* Ack: you pay a penalty now for a separator
* Later, i can optimze to check if one chunk and
* it's a conditional
*/
StringWriter buf = new StringWriter();
IStringTemplateWriter sw = self.Group.GetStringTemplateWriter(buf);
int tmpsize = Write(self, iterValue, sw);
if (tmpsize != Missing)
{
if (seenAValue && _separatorString != null)
{
n += @out.WriteSeparator(_separatorString);
}
// do it to real output stream now
int nw = Write(self, iterValue, @out);
n += nw;
seenAValue = true;
}
}
}
return n;
}