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


C# IEnumerable.GetEnumerator方法代码示例

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

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

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

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

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

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

示例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();
        }
开发者ID:gitter-badger,项目名称:OmniXAML,代码行数:29,代码来源:NodeVisualizer.cs

示例8: RunManaged

    public void RunManaged(IEnumerable task)
    {
        if (task == null)
            return;

        RunManaged(task.GetEnumerator());
    }
开发者ID:Pellucid-Petrus,项目名称:TaskRunner,代码行数:7,代码来源:TaskRunner.cs

示例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;
		}
开发者ID:taliesins,项目名称:talifun-commander,代码行数:32,代码来源:BindingGroup.cs

示例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();
                        }
                    }

                }
            }
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:34,代码来源:UriExtensions.cs

示例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;
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:35,代码来源:UriExtensions.cs

示例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();
       }
 }
开发者ID:yreynhout,项目名称:naughty,代码行数:26,代码来源:BatchedSqlStatementFlusher.cs

示例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;
     }
 }
开发者ID:neismit,项目名称:emds,代码行数:35,代码来源:ImportExcelFileDialog.cs

示例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.");
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:32,代码来源:TimeSeriesPrognosisAutoRegressiveModel.cs

示例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;
        }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:26,代码来源:StartsWithValueConverter.cs


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