本文整理汇总了C#中IEnumerable.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.GetEnumerator方法的具体用法?C# IEnumerable.GetEnumerator怎么用?C# IEnumerable.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertGenericDictionaryToArray
public static List<object> ConvertGenericDictionaryToArray(DataContractJsonSerializer serializer, IEnumerable value, CollectionDataContract dataContract, XmlObjectSerializerWriteContextComplexJson context, bool writeServerType)
{
List<object> keyValuePair = new List<object>();
Dictionary<string, object> currentEntry;
Type[] declaredTypes = dataContract.ItemType.GetGenericArguments();
MethodInfo getEnumeratorMethod = dataContract.GetEnumeratorMethod;
IDictionaryEnumerator enumerator = (IDictionaryEnumerator)((getEnumeratorMethod == null) ? value.GetEnumerator() : (IDictionaryEnumerator)getEnumeratorMethod.Invoke(value, Array.Empty<Type>()));
while (enumerator.MoveNext())
{
DictionaryEntry current = enumerator.Entry;
DataContract currentDataContract = DataContract.GetDataContract(enumerator.Current.GetType());
currentEntry = new Dictionary<string, object>();
if (writeServerType)
{
AddTypeInformation(currentEntry, currentDataContract);
}
context.PushKnownTypes(dataContract);
AddDictionaryEntryData(serializer, currentEntry, writeServerType ? JsonGlobals.KeyString.ToLowerInvariant() : JsonGlobals.KeyString, declaredTypes[0], current.Key, context);
AddDictionaryEntryData(serializer, currentEntry, writeServerType ? JsonGlobals.ValueString.ToLowerInvariant() : JsonGlobals.ValueString, declaredTypes[1], current.Value, context);
keyValuePair.Add(currentEntry);
context.PopKnownTypes(dataContract);
}
return keyValuePair;
}
示例2: M
public static void M(IEnumerable<int> list)
{
foreach (var i in list)
{
Console.WriteLine(i);
}
{
// C# 3.0 以前
var e = list.GetEnumerator();
using (e as IDisposable)
{
int i; // ループの外
while (e.MoveNext())
{
i = e.Current;
Console.WriteLine(i);
}
}
}
{
// C# 4.0 以降
var e = list.GetEnumerator();
using (e as IDisposable)
{
while (e.MoveNext())
{
var i = e.Current; // ループの中
Console.WriteLine(i);
}
}
}
}
示例3: CreateCommands
public static Mock<EnvDTE.Commands> CreateCommands(IEnumerable<EnvDTE.Command> commands)
{
var mock = new Mock<EnvDTE.Commands>(MockBehavior.Strict);
var enumMock = mock.As<IEnumerable>();
mock.Setup(x => x.GetEnumerator()).Returns(commands.GetEnumerator());
enumMock.Setup(x => x.GetEnumerator()).Returns(commands.GetEnumerator());
return mock;
}
示例4: Grid
private Grid(int size, int fileLength, IEnumerable<Tuple<char, Position>> data = null)
{
Size = size;
using (var e = data == null ? null : data.GetEnumerator())
_grid = Ut.NewArray(2 * size - 1, j => Ut.NewArray(2 * size - 1 - Math.Abs(size - 1 - j), i => e != null && e.MoveNext() ? e.Current.Item1 : '.'));
_endPos = new Position(fileLength, 0);
using (var e = data == null ? null : data.GetEnumerator())
_gridPositions = Ut.NewArray(2 * size - 1, j => Ut.NewArray(2 * size - 1 - Math.Abs(size - 1 - j), i => e != null && e.MoveNext() ? e.Current.Item2 : _endPos));
}
示例5: GetType
protected static Type GetType(IEnumerable records)
{
var enumerator = records.GetEnumerator();
if (!enumerator.MoveNext() || enumerator.Current == null)
return typeof(object);
return enumerator.Current.GetType();
}
示例6: ArgumentNotNullOrEmpty
/// <summary/>
public static void ArgumentNotNullOrEmpty(string argName, IEnumerable argValue)
{
ArgumentNotNull(argName, argValue);
if (!argValue.GetEnumerator().MoveNext())
throw new ArgumentException("Argument was empty", argName);
}
示例7: ToTree
public static VisualizationNode ToTree(IEnumerable<XamlNode> xamlNodes)
{
var enumerator = xamlNodes.GetEnumerator();
var stack = new Stack<VisualizationNode>();
stack.Push(new VisualizationNode("Root"));
while (enumerator.MoveNext())
{
var current = enumerator.Current;
if (LowersLevel(current))
{
stack.Pop();
}
else
{
var item = new VisualizationNode(current);
stack.Peek().Children.Add(item);
if (RaisesLevel(current))
{
stack.Push(item);
}
}
}
return stack.Peek();
}
示例8: RunManaged
public void RunManaged(IEnumerable task)
{
if (task == null)
return;
RunManaged(task.GetEnumerator());
}
示例9: GetElementType
public static Type GetElementType(IEnumerable enumerable)
{
Type elementType = null;
var enumerableType = enumerable.GetType();
do
{
if (enumerableType.IsGenericType)
{
var genericArguments = enumerableType.GetGenericArguments();
if (genericArguments.Length > 0)
{
elementType = genericArguments[0];
}
}
enumerableType = enumerableType.BaseType;
} while (elementType == null && enumerableType != null);
if (elementType == null)
{
var enumItems = enumerable.GetEnumerator();
if (enumItems.MoveNext())
{
if (enumItems.Current != null)
{
elementType = enumItems.Current.GetType();
}
}
}
return elementType;
}
示例10: ZipFill
private static IEnumerable<string> ZipFill(this IEnumerable<string> source1, IEnumerable<string> source2, Func<string, string, string> selector)
{
using (var enumerator1 = source1.GetEnumerator())
{
using (var enumerator2 = source2.GetEnumerator())
{
var has1 = enumerator1.MoveNext();
var has2 = enumerator2.MoveNext();
while (has1 || has2)
{
var value1 = has1 ? enumerator1.Current : null;
var value2 = has2 ? enumerator2.Current : null;
var value = selector(value1, value2);
if (value != null)
{
yield return value;
}
if (has1)
{
has1 = enumerator1.MoveNext();
}
if (has2)
{
has2 = enumerator2.MoveNext();
}
}
}
}
}
示例11: ZipCompare
private static bool ZipCompare(this IEnumerable<string> source1, IEnumerable<string> source2, Func<string, string, bool> comparison)
{
using (var enumerator1 = source1.GetEnumerator())
{
using (var enumerator2 = source2.GetEnumerator())
{
var has1 = enumerator1.MoveNext();
var has2 = enumerator2.MoveNext();
while (has1 || has2)
{
var current1 = has1 ? enumerator1.Current : "";
var current2 = has2 ? enumerator2.Current : "";
if (!comparison(current1, current2))
{
return false;
}
if (has1)
{
has1 = enumerator1.MoveNext();
}
if (has2)
{
has2 = enumerator2.MoveNext();
}
}
}
}
return true;
}
示例12: Flush
public void Flush(IEnumerable<ISqlStatement> statements)
{
var writer = new SqlStatementBatchWriter();
using (var connection = new SqlConnection(_builder.ConnectionString)) {
connection.Open();
using (var transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)) {
using (var command = new SqlCommand()) {
command.Connection = connection;
command.Transaction = transaction;
using (var enumerator = statements.GetEnumerator()) {
var moved = enumerator.MoveNext();
while (moved) {
while (moved && writer.TryWrite(enumerator.Current)) {
moved = enumerator.MoveNext();
}
writer.BuildCommand(command);
command.ExecuteNonQuery();
writer.Reset();
}
}
}
transaction.Commit();
}
connection.Close();
}
}
示例13: ImportExcelFileDialog
public ImportExcelFileDialog(IEnumerable<string> names)
{
bool flag;
this.InitializeComponent();
using (IEnumerator<string> enumerator = names.GetEnumerator())
{
string str;
goto Label_0055;
Label_0037:
str = enumerator.Current;
this.cbDataSets.Items.Add(str);
if (0 != 0)
{
goto Label_0037;
}
Label_0055:
if (enumerator.MoveNext())
{
goto Label_0037;
}
goto Label_0086;
}
if (((uint) flag) <= uint.MaxValue)
{
goto Label_0086;
}
Label_000A:
this.cbDataSets.SelectedIndex = 0;
return;
Label_0086:
if (names.Count<string>() > 0)
{
goto Label_000A;
}
}
示例14: GetPrognosedValues
public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {
var rowsEnumerator = rows.GetEnumerator();
var horizonsEnumerator = horizons.GetEnumerator();
var targetValues = dataset.GetReadOnlyDoubleValues(TargetVariable);
// produce a n-step forecast for all rows
while (rowsEnumerator.MoveNext() & horizonsEnumerator.MoveNext()) {
int row = rowsEnumerator.Current;
int horizon = horizonsEnumerator.Current;
if (row - TimeOffset < 0) {
yield return Enumerable.Repeat(double.NaN, horizon);
continue;
}
double[] prognosis = new double[horizon];
for (int h = 0; h < horizon; h++) {
double estimatedValue = 0.0;
for (int i = 1; i <= TimeOffset; i++) {
int offset = h - i;
if (offset >= 0) estimatedValue += prognosis[offset] * Phi[i - 1];
else estimatedValue += targetValues[row + offset] * Phi[i - 1];
}
estimatedValue += Constant;
prognosis[h] = estimatedValue;
}
yield return prognosis;
}
if (rowsEnumerator.MoveNext() || horizonsEnumerator.MoveNext())
throw new ArgumentException("Number of elements in rows and horizon enumerations doesn't match.");
}
示例15: Transform
List<CssToken> Transform(IEnumerable<CssToken> values)
{
var enumerator = values.GetEnumerator();
while (enumerator.MoveNext() && enumerator.Current.Type == CssTokenType.Whitespace)
{
//Empty on purpose.
}
if (enumerator.Current.Type == _type && enumerator.Current.Data.Isi(_data))
{
var list = new List<CssToken>();
while (enumerator.MoveNext())
{
if (enumerator.Current.Type != CssTokenType.Whitespace || list.Count != 0)
{
list.Add(enumerator.Current);
}
}
return list;
}
return null;
}