System.Collections.IEnumerable.GetEnumerator()

Here are the examples of the csharp api System.Collections.IEnumerable.GetEnumerator() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

845 Examples 7

19 View Source File : Detector.cs
License : MIT License
Project Creator : architdate

public DetectorResult detect()
		{
			
			ResultPoint[] cornerPoints = rectangleDetector.detect();
			ResultPoint pointA = cornerPoints[0];
			ResultPoint pointB = cornerPoints[1];
			ResultPoint pointC = cornerPoints[2];
			ResultPoint pointD = cornerPoints[3];
			
			// Point A and D are across the diagonal from one another,
			// as are B and C. Figure out which are the solid black lines
			// by counting transitions
			System.Collections.ArrayList transitions = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(4));
			transitions.Add(transitionsBetween(pointA, pointB));
			transitions.Add(transitionsBetween(pointA, pointC));
			transitions.Add(transitionsBetween(pointB, pointD));
			transitions.Add(transitionsBetween(pointC, pointD));
			Collections.insertionSort(transitions, new ResultPointsAndTransitionsComparator());
			
			// Sort by number of transitions. First two will be the two solid sides; last two
			// will be the two alternating black/white sides
			ResultPointsAndTransitions lSideOne = (ResultPointsAndTransitions) transitions[0];
			ResultPointsAndTransitions lSideTwo = (ResultPointsAndTransitions) transitions[1];
			
			// Figure out which point is their intersection by tallying up the number of times we see the
			// endpoints in the four endpoints. One will show up twice.
			System.Collections.Hashtable pointCount = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
			increment(pointCount, lSideOne.From);
			increment(pointCount, lSideOne.To);
			increment(pointCount, lSideTwo.From);
			increment(pointCount, lSideTwo.To);
			
			ResultPoint maybeTopLeft = null;
			ResultPoint bottomLeft = null;
			ResultPoint maybeBottomRight = null;
			System.Collections.IEnumerator points = pointCount.Keys.GetEnumerator();
			//UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
			while (points.MoveNext())
			{
				//UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
				ResultPoint point = (ResultPoint) points.Current;
				System.Int32 value_Renamed = (System.Int32) pointCount[point];
				if (value_Renamed == 2)
				{
					bottomLeft = point; // this is definitely the bottom left, then -- end of two L sides
				}
				else
				{
					// Otherwise it's either top left or bottom right -- just replacedign the two arbitrarily now
					if (maybeTopLeft == null)
					{
						maybeTopLeft = point;
					}
					else
					{
						maybeBottomRight = point;
					}
				}
			}
			
			if (maybeTopLeft == null || bottomLeft == null || maybeBottomRight == null)
			{
				throw ReaderException.Instance;
			}
			
			// Bottom left is correct but top left and bottom right might be switched
			ResultPoint[] corners = new ResultPoint[]{maybeTopLeft, bottomLeft, maybeBottomRight};
			// Use the dot product trick to sort them out
			ResultPoint.orderBestPatterns(corners);
			
			// Now we know which is which:
			ResultPoint bottomRight = corners[0];
			bottomLeft = corners[1];
			ResultPoint topLeft = corners[2];
			
			// Which point didn't we find in relation to the "L" sides? that's the top right corner
			ResultPoint topRight;
			if (!pointCount.ContainsKey(pointA))
			{
				topRight = pointA;
			}
			else if (!pointCount.ContainsKey(pointB))
			{
				topRight = pointB;
			}
			else if (!pointCount.ContainsKey(pointC))
			{
				topRight = pointC;
			}
			else
			{
				topRight = pointD;
			}
			
			// Next determine the dimension by tracing along the top or right side and counting black/white
			// transitions. Since we start inside a black module, we should see a number of transitions
			// equal to 1 less than the code dimension. Well, actually 2 less, because we are going to
			// end on a black module:
			
			// The top right point is actually the corner of a module, which is one of the two black modules
			// adjacent to the white module at the top right. Tracing to that corner from either the top left
			// or bottom right should work here. The number of transitions could be higher than it should be
			// due to noise. So we try both and take the min.
			
			int dimension = System.Math.Min(transitionsBetween(topLeft, topRight).Transitions, transitionsBetween(bottomRight, topRight).Transitions);
			if ((dimension & 0x01) == 1)
			{
				// it can't be odd, so, round... up?
				dimension++;
			}
			dimension += 2;
			
			BitMatrix bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, dimension);
			return new DetectorResult(bits, new ResultPoint[]{pointA, pointB, pointC, pointD});
		}

19 View Source File : SourceInjectedQueryProvider.cs
License : MIT License
Project Creator : AutoMapper

public TResult Execute<TResult>(Expression expression)
        {
            try
            {
                var resultType = typeof(TResult);
                Inspector.StartQueryExecuteInterceptor(resultType, expression);

                var sourceExpression = ConvertDestinationExpressionToSourceExpression(expression);

                var destResultType = typeof(TResult);
                var sourceResultType = CreateSourceResultType(destResultType);

                object destResult = null;

                // case #1: query is a projection from complex Source to complex Destination
                // example: users.UseAsDataSource().For<UserDto>().Where(x => x.Age > 20).ToList()
                if (IsProjection<TDestination>(resultType))
                {
                    // in case of a projection, we need an IQueryable
                    var sourceResult = _dataSource.Provider.CreateQuery(sourceExpression);
                    Inspector.SourceResult(sourceExpression, sourceResult);
                    
                    var queryExpressions = _mapper.ConfigurationProvider.Internal().ProjectionBuilder.GetProjection
                    (
                        sourceResult.ElementType, 
                        typeof(TDestination),
                        _parameters,
                        _membersToExpand.Select
                        (
                            m => new MemberPath
                            (
                                m.Distinct().ToArray()
                            )
                        ).ToArray()
                    );

                    destResult = (IQueryable<TDestination>)GetMapExpressions(queryExpressions).Aggregate(sourceResult, Select);
                }
                // case #2: query is arbitrary ("manual") projection
                // exaple: users.UseAsDataSource().For<UserDto>().Select(user => user.Age).ToList()
                // in case an arbitrary select-statement is enumerated, we do not need to map the expression at all
                // and cann safely return it
                else if (IsProjection(resultType, sourceExpression))
                {
                    var sourceResult = _dataSource.Provider.CreateQuery(sourceExpression);
                    var enumerator = sourceResult.GetEnumerator();
                    var elementType = ElementTypeHelper.GetElementType(typeof(TResult));
                    var constructorInfo = typeof(List<>).MakeGenericType(elementType).GetDeclaredConstructor(new Type[0]);
                    if (constructorInfo != null)
                    {
                        var listInstance = (IList)constructorInfo.Invoke(null);
                        while (enumerator.MoveNext())
                        {
                            listInstance.Add(enumerator.Current);
                        }
                        destResult = listInstance;
                    }
                }
                // case #2: projection to simple type
                // example: users.UseAsDataSource().For<UserDto>().FirstOrDefault(user => user.Age > 20)
                else
                {
                    /* 
                        in case of an element result (so instead of IQueryable<TResult>, just TResult)
                        we still want to support parameters.
                        This is e.g. the case, when the developer writes "UseAsDataSource().For<TResult>().FirstOrDefault(x => ...)
                        To still be able to support parameters, we need to create a query from it. 
                        That said, we need to replace the "element" operator "FirstOrDefault" with a "Where" operator, then apply our "Select" 
                        to map from TSource to TResult and finally re-apply the "element" operator ("FirstOrDefault" in our case) so only
                        one element is returned by our "Execute<TResult>" method. Otherwise we'd get an InvalidCastException

                        * So first we visit the sourceExpression and replace "element operators" with "where"
                        * then we create our mapping expression from TSource to TDestination (select) and apply it
                        * finally, we search for the element expression overload of our replaced "element operator" that has no expression as parameter
                            this expression is not needed anymore as it has already been applied to the "Where" operation and can be safely omitted
                        * when we're done creating our new expression, we call the underlying provider to execute it
                    */

                    // as we need to replace the innermost element of the expression,
                    // we need to traverse it first in order to find the node to replace or potential caveats
                    // e.g. .UseAsDataSource().For<Dto>().Select(e => e.Name).First()
                    //      in the above case we cannot map anymore as the "select" operator overrides our mapping.
                    var searcher = new ReplaceableMethodNodeFinder<TSource>();
                    searcher.Visit(sourceExpression);
                    // provide the replacer with our found MethodNode or <null>
                    var replacer = new MethodNodeReplacer<TSource>(searcher.MethodNode);

                    // default back to simple mapping of object instance for backwards compatibility (e.g. mapping non-nullable to nullable fields)
                    sourceExpression = replacer.Visit(sourceExpression);

                    if (replacer.FoundElementOperator)
                    {
                        /*  in case of primitive element operators (e.g. Any(), Sum()...)
                            we need to map the originating types (e.g. Enreplacedy to Dto) in this query
                            as the final value will be projected automatically
                            
                            == example 1 ==
                            UseAsDataSource().For<Dto>().Any(enreplacedy => enreplacedy.Name == "thename")
                            ..in that case sourceResultType and destResultType would both be "Boolean" which is not mappable for AutoMapper

                            == example 2 ==
                            UseAsDataSource().For<Dto>().FirstOrDefault(enreplacedy => enreplacedy.Name == "thename")
                            ..in this case the sourceResultType would be Enreplacedy and the destResultType Dto, so we can map the query directly
                        */

                        if (sourceResultType == destResultType)// && destResultType.IsPrimitive)
                        {
                            sourceResultType = typeof(TSource);
                            destResultType = typeof(TDestination);
                        }

                        var queryExpressions = _mapper.ConfigurationProvider.Internal().ProjectionBuilder.GetProjection
                        (
                            sourceResultType, 
                            destResultType, 
                            _parameters,
                            _membersToExpand.Select
                            (
                                m => new MemberPath
                                (
                                    m.Distinct().ToArray()
                                )
                            ).ToArray()
                        );
                        // add projection via "select" operator
                        var expr = GetMapExpressions(queryExpressions).Aggregate(sourceExpression, (source, lambda) => Select(source, lambda));
                        // in case an element operator without predicate expression was found (and thus not replaced)
                        var replacementMethod = replacer.ElementOperator;
                        // in case an element operator with predicate expression was replaced
                        if (replacer.ReplacedMethod != null)
                        {
                            // find replacement method that has no more predicates
                            replacementMethod = typeof(Queryable).GetAllMethods()
                                .Single(m => m.Name == replacer.ReplacedMethod.Name
#if NET45
                                            && m.GetParameters().All(p => typeof(Queryable).IsreplacedignableFrom(p.Member.ReflectedType))
#endif
                                            && m.GetParameters().Length == replacer.ReplacedMethod.GetParameters().Length - 1);
                        }

                        // reintroduce element operator that was replaced with a "where" operator to make it queryable
                        expr = Call(null,
                            replacementMethod.MakeGenericMethod(destResultType), expr);

                        destResult = _dataSource.Provider.Execute(expr);
                    }
                    // If there was no element operator that needed to be replaced by "where", just map the result
                    else
                    {
                        var sourceResult = _dataSource.Provider.Execute(sourceExpression);
                        Inspector.SourceResult(sourceExpression, sourceResult);
                        destResult = _mapper.Map(sourceResult, sourceResultType, destResultType);
                    }
                }

                Inspector.DestResult(destResult);

                // implicitly convert types in case of valuetypes which cannot be casted explicitly
                if (typeof(TResult).IsValueType() && destResult?.GetType() != typeof(TResult))
                    return (TResult)System.Convert.ChangeType(destResult, typeof(TResult));

                // if it is not a valuetype, we can safely cast it
                return (TResult)destResult;
            }
            catch (Exception x)
            {
                _exceptionHandler(x);
                throw;
            }
        }

19 View Source File : CollectionIsExtensions.cs
License : MIT License
Project Creator : aljazsim

public static bool IsNullOrEmpty<T>(this T value) where T : IEnumerable
        {
            if (value == null)
            {
                return true;
            }
            else
            {
                return !value.GetEnumerator().MoveNext();
            }
        }

19 View Source File : ForEachTag.cs
License : MIT License
Project Creator : aprilyush

public override void RenderTagData(System.IO.TextWriter writer)
        {
            IEnumerable array = Utility.GetResolvedDataSource(this.From.GetValue());
            int index = 0;
            LoopIndex li = new LoopIndex(0);
            if (this.Index != null) this.Index.Value = li;
            if (array != null)
            {
                IEnumerator list = array.GetEnumerator();
                int groupSize = this.GroupSize == null ? 0 : Utility.ConverToInt32(this.GroupSize.GetTextValue());
                if (groupSize > 1) list = Utility.SplitToGroup(list, groupSize);

                list.Reset();
                if (list.MoveNext())
                {
                    li.IsLast = false;
                    while (!li.IsLast)
                    {
                        object v = list.Current;
                        li.Value = ++index;
                        li.IsFirst = (index == 1);
                        li.IsLast = !list.MoveNext();
                        if (this.Index != null) this.Index.Reset();
                        if (this.Item != null) this.Item.Value = v;
                        base.RenderTagData(writer);
                    }
                }
            }
            if (index == 0 && this.Else != null)
            {
                //没有数据则输出Else节点的数据
                this.Else.Render(writer);
            }
        }

19 View Source File : Utils.cs
License : Apache License 2.0
Project Creator : AnthonyLloyd

public static bool Equal<T>(T a, T b)
        {
            if (a is IEquatable<T> aieq) return aieq.Equals(b);
            else if (a is Array aa2 && b is Array ba2 && aa2.Rank == 2)
            {
                int I = aa2.GetLength(0), J = aa2.GetLength(1);
                if (I != ba2.GetLength(0) || J != ba2.GetLength(1)) return false;
                for (int i = 0; i < I; i++)
                    for (int j = 0; j < J; j++)
                        if (!aa2.GetValue(i, j).Equals(ba2.GetValue(i, j)))
                            return false;
                return true;
            }
            else if (a is IList ail && b is IList bil)
            {
                if (ail.Count != bil.Count) return false;
                for (int i = 0; i < ail.Count; i++)
                    if (!ail[i].Equals(bil[i]))
                        return false;
                return true;
            }
            else if (a.GetType().GetInterface(typeof(IReadOnlyList<>).Name) != null)
            {
                var e1 = ((IEnumerable)a).GetEnumerator();
                var e2 = ((IEnumerable)b).GetEnumerator();
                while (true)
                {
                    var e1MoveNext = e1.MoveNext();
                    if (e1MoveNext != e2.MoveNext()) return false;
                    if (!e1MoveNext) return true;
                    if (!Equal(e1.Current, e2.Current)) return false;
                }
            }
            else if (a is ICollection aic && b is ICollection bic)
            {
                return aic.Count == bic.Count && !aic.Cast<object>().Except(bic.Cast<object>()).Any();
            }
            else if (a is IEnumerable aie && b is IEnumerable bie)
            {
                var aieo = aie.Cast<object>().ToList();
                var bieo = bie.Cast<object>().ToList();
                return aieo.Count == bieo.Count && !aieo.Except(bieo).Any();
            }
            return a.Equals(b);
        }

19 View Source File : TestObserver.cs
License : Apache License 2.0
Project Creator : akarnokd

void compareEnums(IEnumerable expected, IEnumerable actual, int index)
        {
            IEnumerator exp = expected.GetEnumerator();
            IEnumerator act = actual.GetEnumerator();

            int j = 0;
            for (; ; )
            {
                bool expNext = exp.MoveNext();
                bool actNext = act.MoveNext();

                if (!expNext && !actNext)
                {
                    break;
                }
                else
                if (expNext && actNext)
                {
                    if (!Equals(exp.Current, act.Current))
                    {
                        throw Fail("Item @ " + index + "/" + j + " differ. Expected: " + ToStr(exp.Current) + ", Actual: " + ToStr(act.Current));
                    }
                }
                else
                if (expNext && !actNext)
                {
                    throw Fail("Item @ " + index + ", more items expected from the IEnumerable");
                }
                else
                {
                    throw Fail("Item @ " + index + ", less items expected from the IEnumerable");
                }

                j++;
            }
        }

19 View Source File : Brush.cs
License : GNU General Public License v3.0
Project Creator : arklumpus

IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)gradientStops).GetEnumerator();
        }

19 View Source File : ProgressIndicator.cs
License : MIT License
Project Creator : Adoxio

protected int RenderTypeNumeric(IEnumerable dataSource)
		{
			var count = 0;
			var progressIndex = 0;
			var clreplacedName = "progress-numeric";
			
			var e = dataSource.GetEnumerator();

			if (string.IsNullOrWhiteSpace(Position))
			{
				CssClreplaced = string.Join(" ", CssClreplaced, clreplacedName);
			}
			else
			{
				switch (Position.ToLowerInvariant())
				{
					case "top":
						clreplacedName += " top";
						break;
					case "bottom":
						clreplacedName += " bottom";
						break;
					case "left":
						clreplacedName += " left";
						CssClreplaced += " col-sm-3 col-md-2";
						break;
					case "right":
						clreplacedName += " right";
						CssClreplaced += " col-sm-3 col-sm-push-9 col-md-2 col-md-push-10";
						break;
				}

				CssClreplaced = string.Join(" ", CssClreplaced, clreplacedName);
			}

			while (e.MoveNext())
			{
				if (e.Current == null)
				{
					continue;
				}

				var indexValue = DataBinder.GetPropertyValue(e.Current, IndexDataPropertyName);
				var activeValue = DataBinder.GetPropertyValue(e.Current, ActiveDataPropertyName);
				var index = Convert.ToInt32(indexValue);
				var active = Convert.ToBoolean(activeValue);

				if (active)
				{
					progressIndex = ZeroBasedIndex ? index + 1 : index;
				}

				count++;
			}

			var literal = new LiteralControl { Text = string.Format("{0} <span clreplaced='number'>{1}</span> of <span clreplaced='number total'>{2}</span>", NumericPrefix, progressIndex, count) };
			
			Controls.Add(literal);

			return count;
		}

19 View Source File : IQueryableExtensions.cs
License : MIT License
Project Creator : Avanade

public static IQueryable<TElement> WhereWith<TElement, T>(this IQueryable<TElement> query, T with, Expression<Func<TElement, bool>> predicate)
        {
            Check.NotNull(query, nameof(query));
            if (Comparer<T>.Default.Compare(with, default!) != 0 && Comparer<T>.Default.Compare(with, default!) != 0)
            {
                if (!(with is string) && with is System.Collections.IEnumerable ie && !ie.GetEnumerator().MoveNext())
                    return query;

                return query.Where(predicate);
            }
            else
                return query;
        }

19 View Source File : AttachableCollection!1.cs
License : GNU General Public License v3.0
Project Creator : aduskin

private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    var enumerator1 = e.NewItems.GetEnumerator();
                    try
                    {
                        while (enumerator1.MoveNext())
                        {
                            var current = (T) enumerator1.Current;
                            try
                            {
                                VerifyAdd(current);
                                ItemAdded(current);
                            }
                            finally
                            {
                                _snapshot.Insert(IndexOf(current), current);
                            }
                        }
                        break;
                    }
                    finally
                    {
                        if (enumerator1 is IDisposable disposable)
                            disposable.Dispose();
                    }
                case NotifyCollectionChangedAction.Remove:
                    var enumerator2 = e.OldItems.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            var current = (T) enumerator2.Current;
                            ItemRemoved(current);
                            _snapshot.Remove(current);
                        }
                        break;
                    }
                    finally
                    {
                        if (enumerator2 is IDisposable disposable)
                            disposable.Dispose();
                    }
                case NotifyCollectionChangedAction.Replace:
                    foreach (T oldItem in e.OldItems)
                    {
                        ItemRemoved(oldItem);
                        _snapshot.Remove(oldItem);
                    }
                    var enumerator3 = e.NewItems.GetEnumerator();
                    try
                    {
                        while (enumerator3.MoveNext())
                        {
                            var current = (T) enumerator3.Current;
                            try
                            {
                                VerifyAdd(current);
                                ItemAdded(current);
                            }
                            finally
                            {
                                _snapshot.Insert(IndexOf(current), current);
                            }
                        }
                        break;
                    }
                    finally
                    {
                        if (enumerator3 is IDisposable disposable)
                            disposable.Dispose();
                    }
                case NotifyCollectionChangedAction.Reset:
                    foreach (var obj in _snapshot)
                        ItemRemoved(obj);
                    _snapshot = new Collection<T>();
                    using (var enumerator4 = GetEnumerator())
                    {
                        while (enumerator4.MoveNext())
                        {
                            var current = enumerator4.Current;
                            VerifyAdd(current);
                            ItemAdded(current);
                        }
                        break;
                    }
            }
        }

19 View Source File : ExcelWorksheet.cs
License : Apache License 2.0
Project Creator : Appdynamics

private void UpdateRowCellData(StreamWriter sw)
        {
            ExcelStyleCollection<ExcelXfs> cellXfs = _package.Workbook.Styles.CellXfs;

            int row = -1;

            StringBuilder sbXml = new StringBuilder();
            var ss = _package.Workbook._sharedStrings;
            var styles = _package.Workbook.Styles;
            var cache = new StringBuilder();
            cache.Append("<sheetData>");

            
            FixSharedFormulas(); //Fixes Issue #32

            columnStyles = new Dictionary<int, int>();
            var cse = new CellsStoreEnumerator<ExcelCoreValue>(_values, 1, 0, ExcelPackage.MaxRows, ExcelPackage.MaxColumns);
            while (cse.Next())
            {
                if (cse.Column > 0)
                {
                    var val = cse.Value;
                    //int styleID = cellXfs[styles.GetStyleId(this, cse.Row, cse.Column)].newID;
                    int styleID = cellXfs[(val._styleId == 0 ? GetStyleIdDefaultWithMemo(cse.Row, cse.Column) : val._styleId)].newID;
                    //Add the row element if it's a new row
                    if (cse.Row != row)
                    {
                        WriteRow(cache, cellXfs, row, cse.Row);
                        row = cse.Row;
                    }
                    object v = val._value;
                    object formula = _formulas.GetValue(cse.Row, cse.Column);
                    if (formula is int)
                    {
                        int sfId = (int)formula;
                        var f = _sharedFormulas[(int)sfId];
                        if (f.Address.IndexOf(':') > 0)
                        {
                            if (f.StartCol == cse.Column && f.StartRow == cse.Row)
                            {
                                if (f.IsArray)
                                {
                                    cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{5}><f ref=\"{2}\" t=\"array\">{3}</f>{4}</c>", cse.CellAddress, styleID < 0 ? 0 : styleID, f.Address, ConvertUtil.ExcelEscapeString(f.Formula), GetFormulaValue(v), GetCellType(v, true));
                                }
                                else
                                {
                                    cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{6}><f ref=\"{2}\" t=\"shared\" si=\"{3}\">{4}</f>{5}</c>", cse.CellAddress, styleID < 0 ? 0 : styleID, f.Address, sfId, ConvertUtil.ExcelEscapeString(f.Formula), GetFormulaValue(v), GetCellType(v, true));
                                }

                            }
                            else if (f.IsArray)
                            {
                                cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"/>", cse.CellAddress, styleID < 0 ? 0 : styleID);
                            }
                            else
                            {
                                cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{4}><f t=\"shared\" si=\"{2}\"/>{3}</c>", cse.CellAddress, styleID < 0 ? 0 : styleID, sfId, GetFormulaValue(v), GetCellType(v, true));
                            }
                        }
                        else
                        {
                            // We can also have a single cell array formula
                            if (f.IsArray)
                            {
                                cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{5}><f ref=\"{2}\" t=\"array\">{3}</f>{4}</c>", cse.CellAddress, styleID < 0 ? 0 : styleID, string.Format("{0}:{1}", f.Address, f.Address), ConvertUtil.ExcelEscapeString(f.Formula), GetFormulaValue(v), GetCellType(v, true));
                            }
                            else
                            {
                                cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{2}>", f.Address, styleID < 0 ? 0 : styleID, GetCellType(v, true));
                                cache.AppendFormat("<f>{0}</f>{1}</c>", ConvertUtil.ExcelEscapeString(f.Formula), GetFormulaValue(v));
                            }
                        }
                    }
                    else if (formula != null && formula.ToString() != "")
                    {
                        cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{2}>", cse.CellAddress, styleID < 0 ? 0 : styleID, GetCellType(v, true));
                        cache.AppendFormat("<f>{0}</f>{1}</c>", ConvertUtil.ExcelEscapeString(formula.ToString()), GetFormulaValue(v));
                    }
                    else
                    {
                        if (v == null && styleID > 0)
                        {
                            cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"/>", cse.CellAddress, styleID < 0 ? 0 : styleID);
                        }
                        else if (v != null)
                        {
                            // Fix for issue 15460
                            var enumerableResult = v as System.Collections.IEnumerable;
                            if (enumerableResult != null && !(v is string))
                            {
                                var enumerator = enumerableResult.GetEnumerator();
                                if (enumerator.MoveNext() && enumerator.Current != null)
                                    v = enumerator.Current;
                                else
                                    v = string.Empty;
                            }
                            if ((TypeCompat.IsPrimitive(v) || v is double || v is decimal || v is DateTime || v is TimeSpan))
                            {
                                //string sv = GetValueForXml(v);
                                cache.AppendFormat("<c r=\"{0}\" s=\"{1}\"{2}>", cse.CellAddress, styleID < 0 ? 0 : styleID, GetCellType(v));
                                cache.AppendFormat("{0}</c>", GetFormulaValue(v));
                            }
                            else
                            {
                                var vString = Convert.ToString(v);
                                int ix;
                                if (!ss.ContainsKey(vString))
                                {
                                    ix = ss.Count;
                                    ss.Add(vString, new ExcelWorkbook.SharedStringItem() { isRichText = _flags.GetFlagValue(cse.Row, cse.Column, CellFlags.RichText), pos = ix });
                                }
                                else
                                {
                                    ix = ss[vString].pos;
                                }
                                cache.AppendFormat("<c r=\"{0}\" s=\"{1}\" t=\"s\">", cse.CellAddress, styleID < 0 ? 0 : styleID);
                                cache.AppendFormat("<v>{0}</v></c>", ix);
                            }
                        }
                    }
                    ////Update hyperlinks.
                    //if (cell.Hyperlink != null)
                    //{
                    //    _hyperLinkCells.Add(cell.CellID);
                    //}
                }
                else  //ExcelRow
                {
                    //int newRow=((ExcelRow)cse.Value).Row;
                    WriteRow(cache, cellXfs, row, cse.Row);
                    row = cse.Row;
                }
                if (cache.Length > 0x600000)
                {
                    sw.Write(cache.ToString());
                    sw.Flush();
                    cache.Length = 0;
                }
            }
            columnStyles = null;

            if (row != -1) cache.Append("</row>");
            cache.Append("</sheetData>");
            sw.Write(cache.ToString());
            sw.Flush();
        }

19 View Source File : ReadOnlyPropertiesDictionary.cs
License : Apache License 2.0
Project Creator : apache

IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable)InnerHashtable).GetEnumerator();
		}

19 View Source File : ReadOnlySet.cs
License : MIT License
Project Creator : Aiko-IT-Systems

[MethodImpl(MethodImplOptions.AggressiveInlining)]
        IEnumerator IEnumerable.GetEnumerator()
            => (this._underlyingSet as IEnumerable).GetEnumerator();

19 View Source File : VariableTag.cs
License : MIT License
Project Creator : aprilyush

public override void Render(System.IO.TextWriter writer)
        {
            VariableTag tag = this;
            object value = this.VarExpression.GetValue();

            //调用自定函数处理此变量的值
            if (this.CallFunctions.Count > 0)
            {
                foreach (var exp in this.CallFunctions)
                {
                    object method = exp.GetValue();
                    if (!Utility.IsNothing(method))
                    {
                        UserDefinedFunction func;
                        if (this.OwnerTemplate.UserDefinedFunctions.TryGetValue(method.ToString(), out func))
                        {
                            value = func(new object[] { value });
                        }
                    }
                }
            }

            if (Utility.IsNothing(value)) return;

            bool formated = false;
            string text = string.Empty;
            string format = this.Format == null ? string.Empty : this.Format.GetTextValue();
            if (value is string)
            {
                //字符串
                text = (string)value;
            }
            else
            {                
                //非字符串.则判断处理format
                if (!string.IsNullOrEmpty(format))
                {
                    IFormattable iformat = value as IFormattable;
                    if (iformat != null)
                    {
                        text = iformat.ToString(format, CultureInfo.InvariantCulture);
                        formated = true;
                    }
                }
                //非IFormattable接口.则直接取字符串处理
                if (!formated)
                {
                    //如果数据是IEnumerable,IEnumerator接口则进行数据拼凑
                    IEnumerator ie = null;
                    if (value is IEnumerable)
                    {
                        ie = ((IEnumerable)value).GetEnumerator();
                    }
                    else if (value is IEnumerator)
                    {
                        ie = (IEnumerator)value;
                    }
                    if (ie != null)
                    {
                        StringBuilder buffer = new StringBuilder();
                        ie.Reset();
                        while (ie.MoveNext())
                        {
                            if (buffer.Length != 0) buffer.Append(",");
                            buffer.Append(ie.Current);
                        }
                        text = buffer.ToString();
                    }
                    else
                    {
                        text = value.ToString();
                    }
                }
            }

            if (text.Length > 0)
            {
                bool removeHtml = this.RemoveHtml == null ? false : Utility.ConverToBoolean(this.RemoveHtml.GetTextValue());
                bool textEncode = this.TextEncode == null ? false : Utility.ConverToBoolean(this.TextEncode.GetTextValue());
                bool htmlEncode = this.HtmlEncode == null ? false : Utility.ConverToBoolean(this.HtmlEncode.GetTextValue());
                bool xmlEncode = this.XmlEncode == null ? false : Utility.ConverToBoolean(this.XmlEncode.GetTextValue());                
                bool jsEncode = this.JsEncode == null ? false : Utility.ConverToBoolean(this.JsEncode.GetTextValue());
                bool urlEncode = this.UrlEncode == null ? false : Utility.ConverToBoolean(this.UrlEncode.GetTextValue());
                bool compressText = this.CompressText == null ? false : Utility.ConverToBoolean(this.CompressText.GetTextValue());

                int length = this.Length == null ? 0 : Utility.ConverToInt32(this.Length.GetTextValue());
                string appendText = this.AppendText == null ? string.Empty : this.AppendText.GetTextValue();
                //Encoding charset = this.Charset == null ? this.OwnerTemplate.Charset : Utility.GetEncodingFromCharset(this.Charset.GetTextValue(), this.OwnerTemplate.Charset);
                Encoding charset = Encoding.UTF8;
                if (removeHtml) text = Utility.RemoveHtmlCode(text);
                if (length > 0) text = Utility.CutString(text, length, charset, appendText);
                if (textEncode)
                {
                    text = Utility.TextEncode(text);
                }
                else if (htmlEncode)
                {
                    text = HttpUtility.HtmlEncode(text);
                }
                if (xmlEncode) text = Utility.XmlEncode(text);
                if (jsEncode) text = Utility.JsEncode(text);
                if (urlEncode) text = HttpUtility.UrlEncode(text, charset);
                if (compressText) text = Utility.CompressText(text);

                if (!formated && !string.IsNullOrEmpty(format))
                {
                    text = string.Format(format, text);
                }
                

                writer.Write(text);
            }
        }

19 View Source File : ProgressIndicator.cs
License : MIT License
Project Creator : Adoxio

protected int RenderTypereplacedle(IEnumerable dataSource)
		{
			var count = 0;
			var clreplacedName = "progress list-group";
			var controlContainer = new HtmlGenericControl("ol");
			var e = dataSource.GetEnumerator();

			if (string.IsNullOrWhiteSpace(Position))
			{
				controlContainer.Attributes["clreplaced"] = clreplacedName;
			}
			else
			{
				switch (Position.ToLowerInvariant())
				{
					case "top":
						clreplacedName += " top";
						break;
					case "bottom":
						clreplacedName += " bottom";
						break;
					case "left":
						clreplacedName += " left";
						CssClreplaced += " col-sm-3 col-md-2";
						break;
					case "right":
						clreplacedName += " right";
						CssClreplaced += " col-sm-3 col-sm-push-9 col-md-2 col-md-push-10";
						break;
				}

				controlContainer.Attributes["clreplaced"] = clreplacedName;
			}

			while (e.MoveNext())
			{
				AddStep(e.Current, controlContainer);
				count++;
			}

			Controls.Add(controlContainer);

			return count;
		}

19 View Source File : PooledLinkedList.cs
License : MIT License
Project Creator : ArchonInteractive

IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable) _list).GetEnumerator();
        }

19 View Source File : EditorHelper.cs
License : MIT License
Project Creator : alen-smajic

private static object GetValue_Imp(object source, string name, int index)
		{
			var enumerable = GetValue_Imp(source, name) as System.Collections.IEnumerable;
			if (enumerable == null) return null;
			var enm = enumerable.GetEnumerator();

			for (int i = 0; i <= index; i++)
			{
				if (!enm.MoveNext()) return null;
			}
			return enm.Current;
		}

19 View Source File : TagContainer.cs
License : MIT License
Project Creator : AshleighAdams

IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Tags).GetEnumerator();

19 View Source File : TemplateValidationErrors.cs
License : MIT License
Project Creator : actions

IEnumerator IEnumerable.GetEnumerator()
        {
            return (m_errors as IEnumerable).GetEnumerator();
        }

19 View Source File : IBoundClientExtensions.cs
License : MIT License
Project Creator : Avanade

public static IBoundClient<TElement> FilterWith<TElement, T>(this IBoundClient<TElement> query, T with, Expression<Func<TElement, bool>> predicate) where TElement : clreplaced
        {
            var q = Check.NotNull(query, nameof(query));
            if (Comparer<T>.Default.Compare(with, default!) != 0 && Comparer<T>.Default.Compare(with, default!) != 0)
            {
                if (!(with is string) && with is System.Collections.IEnumerable ie && !ie.GetEnumerator().MoveNext())
                    return q;

                return q.Filter(predicate);
            }
            else
                return q;
        }

19 View Source File : TCollections.cs
License : MIT License
Project Creator : aloneguid

public static bool Equals (IEnumerable first, IEnumerable second)
        {
            if (first == null && second == null)
            {
                return true;
            }
            if (first == null || second == null)
            {
                return false;
            }
            IEnumerator fiter = first.GetEnumerator ();
            IEnumerator siter = second.GetEnumerator ();

            bool fnext = fiter.MoveNext ();
            bool snext = siter.MoveNext ();
            while (fnext && snext)
            {
                IEnumerable fenum = fiter.Current as IEnumerable;
                IEnumerable senum = siter.Current as IEnumerable;
                if (fenum != null && senum != null)
                {
                    if (!Equals(fenum, senum))
                    {
                        return false;
                    }
                }
                else if (fenum == null ^ senum == null)
                {
                    return false;
                }
                else if (!Equals(fiter.Current, siter.Current))
                {
                    return false;
                }
                fnext = fiter.MoveNext();
                snext = siter.MoveNext();
            }

            return fnext == snext;
        }

19 View Source File : Utils.cs
License : Apache License 2.0
Project Creator : AnthonyLloyd

public static bool ModelEqual<T, M>(T actual, M model)
        {
            if (actual is IList ail && model is IList bil)
            {
                if (ail.Count != bil.Count) return false;
                for (int i = 0; i < ail.Count; i++)
                    if (!ail[i].Equals(bil[i]))
                        return false;
                return true;
            }
            else if (actual.GetType().GetInterface(typeof(IReadOnlyList<>).Name) != null
                  && model.GetType().GetInterface(typeof(IReadOnlyList<>).Name) != null)
            {
                var e1 = ((IEnumerable)actual).GetEnumerator();
                var e2 = ((IEnumerable)model).GetEnumerator();
                while (true)
                {
                    var e1MoveNext = e1.MoveNext();
                    if (e1MoveNext != e2.MoveNext()) return false;
                    if (!e1MoveNext) return true;
                    if (!Equal(e1.Current, e2.Current)) return false;
                }
            }
            else if (actual is ICollection aic && model is ICollection bic)
            {
                return aic.Count == bic.Count && !aic.Cast<object>().Except(bic.Cast<object>()).Any();
            }
            else if (actual is IEnumerable aie && model is IEnumerable bie)
            {
                var aieo = aie.Cast<object>().ToList();
                var bieo = bie.Cast<object>().ToList();
                return aieo.Count == bieo.Count && !aieo.Except(bieo).Any();
            }
            return actual.Equals(model);
        }

19 View Source File : PropertiesCollection.cs
License : MIT License
Project Creator : actions

IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)m_innerDictionary).GetEnumerator();
        }

19 View Source File : ConversionSupport.cs
License : Apache License 2.0
Project Creator : apache

public static Amqp.Types.Map MapToAmqp(IDictionary dictionary)
        {
            if (dictionary == null) return null;
            /*if (dictionary is Amqp.Types.Map)
            {
                Amqp.Types.Map DictMap = dictionary as Amqp.Types.Map;
                
                return DictMap.Clone() as Amqp.Types.Map;
            }*/
            Amqp.Types.Map map = new Amqp.Types.Map();
            IEnumerator iterator = dictionary.Keys.GetEnumerator();
            iterator.MoveNext();
            object key = iterator.Current;
            if (key == null) return null;
            object value = null;
            do
            {
                value = dictionary[key];
                if (value != null)
                {
                    Type valtype = value.GetType();
                    if (value is IDictionary)
                    {
                        map[key] = ConversionSupport.MapToAmqp(value as IDictionary);
                    }
                    else if (value is IList)
                    {
                        map[key] = ConversionSupport.ListToAmqp(value as IList);
                    }
                    else if (IsNMSType(value))
                    //else if (valtype.IsPrimitive || value is byte[] || value is String)
                    {
                        map[key] = value;
                    }
                    else
                    {
                        Tracer.InfoFormat("Failed to convert IDictionary[{0}], value{1} to Map value: Invalid Type: {2}", 
                            key, value.ToString(), valtype.Name);
                    }

                }

            }
            while (iterator.MoveNext() && (key = iterator.Current) != null);
            return map;
        }

19 View Source File : ImportService.cs
License : Apache License 2.0
Project Creator : Aguafrommars

private async Task ImportSubEnreplacediesAsync(T enreplacedy, Dictionary<string, IEnumerable> subEnreplacedies, IAdminStore<T> store, ImportFileResult result)
            {                
                if (!subEnreplacedies.Any())
                {
                    return;
                }

                var expand = string.Join(",", subEnreplacedies.Keys);
                enreplacedy = await store.GetAsync(enreplacedy.Id, new GetRequest { Expand = expand }).ConfigureAwait(false);

                foreach (var key in subEnreplacedies.Keys)
                {
                    if (subEnreplacedies[key] == null)
                    {
                        continue;
                    }

                    var property = typeof(T).GetProperty(key);
                    var subEnreplacedyList = property.GetValue(enreplacedy) as IEnumerable;
                    var enreplacedyType = property.PropertyType.GetGenericArguments()[0];
                    var importerType = typeof(Importer<>).MakeGenericType(enreplacedyType);
                    var importer = Activator.CreateInstance(importerType, _provider) as Importer;
                    await importer.RemoveEnreplacediesAsync(subEnreplacedyList, result).ConfigureAwait(false);
                }

                foreach (var enreplacedyList in subEnreplacedies)
                {
                    var enumerator = enreplacedyList.Value.GetEnumerator();
                    if (!enumerator.MoveNext())
                    {
                        continue;
                    }

                    var enreplacedyType = enumerator.Current.GetType();
                    var importerType = typeof(Importer<>).MakeGenericType(enreplacedyType);
                    var importer = Activator.CreateInstance(importerType, _provider) as Importer;

                    await importer.AddOrUpdateSubEnreplacediesAsync(enreplacedyList.Value, result).ConfigureAwait(false);
                }
            }

19 View Source File : DefaultRenderer.cs
License : Apache License 2.0
Project Creator : apache

public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
		{
			if (rendererMap == null)
			{
				throw new ArgumentNullException("rendererMap");
			}

			if (obj == null)
			{
				writer.Write(SystemInfo.NullText);
				return;
			}
			
			Array objArray = obj as Array;
			if (objArray != null)
			{
				RenderArray(rendererMap, objArray, writer);
				return;
			}

			// Test if we are dealing with some form of collection object
			IEnumerable objEnumerable = obj as IEnumerable;
			if (objEnumerable != null)
			{
				// Get a collection interface if we can as its .Count property may be more
				// performant than getting the IEnumerator object and trying to advance it.
				ICollection objCollection = obj as ICollection;
				if (objCollection != null && objCollection.Count == 0)
				{
					writer.Write("{}");
					return;
				}
				
				// This is a special check to allow us to get the enumerator from the IDictionary
				// interface as this guarantees us DictionaryEntry objects. Note that in .NET 2.0
				// the generic IDictionary<> interface enumerates KeyValuePair objects rather than
				// DictionaryEntry ones. However the implementation of the plain IDictionary 
				// interface on the generic Dictionary<> still returns DictionaryEntry objects.
				IDictionary objDictionary = obj as IDictionary;
				if (objDictionary != null)
				{
					RenderEnumerator(rendererMap, objDictionary.GetEnumerator(), writer);
					return;
				}

				RenderEnumerator(rendererMap, objEnumerable.GetEnumerator(), writer);
				return;
			}

			IEnumerator objEnumerator = obj as IEnumerator;
			if (objEnumerator != null)
			{
				RenderEnumerator(rendererMap, objEnumerator, writer);
				return;
			}
			
			if (obj is DictionaryEntry)
			{
				RenderDictionaryEntry(rendererMap, (DictionaryEntry)obj, writer);
				return;
			}

			string str = obj.ToString();
			writer.Write( (str==null) ? SystemInfo.NullText : str );
		}

19 View Source File : Logger.cs
License : Apache License 2.0
Project Creator : apache

[Test]
		public void TestAppender2()
		{
			CountingAppender a1 = new CountingAppender();
			a1.Name = "testAppender2.1";
			CountingAppender a2 = new CountingAppender();
			a2.Name = "testAppender2.2";

			log = (Logger)Utils.GetLogger("test").Logger;
			log.AddAppender(a1);
			log.AddAppender(a2);

			CountingAppender aHat = (CountingAppender)log.GetAppender(a1.Name);
			replacedert.AreEqual(a1, aHat);

			aHat = (CountingAppender)log.GetAppender(a2.Name);
			replacedert.AreEqual(a2, aHat);

			log.RemoveAppender("testAppender2.1");

			IEnumerator enumAppenders = ((IEnumerable)log.Appenders).GetEnumerator();
			replacedert.IsTrue(enumAppenders.MoveNext());
			aHat = (CountingAppender)enumAppenders.Current;
			replacedert.AreEqual(a2, aHat);
			replacedert.IsTrue(!enumAppenders.MoveNext());

			aHat = (CountingAppender)log.GetAppender(a2.Name);
			replacedert.AreEqual(a2, aHat);
		}

19 View Source File : ReadOnlyConcurrentDictionary.cs
License : MIT License
Project Creator : Aiko-IT-Systems

[MethodImpl(MethodImplOptions.AggressiveInlining)]
        IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this._underlyingDict).GetEnumerator();

19 View Source File : IgnoredRoutesConfiguration.cs
License : Apache License 2.0
Project Creator : AppMetrics

IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_stringListImplementation).GetEnumerator(); }

19 View Source File : FixedDictionary.cs
License : MIT License
Project Creator : adamant

[DebuggerStepThrough]
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)items).GetEnumerator();
        }

19 View Source File : Utility.cs
License : MIT License
Project Creator : aprilyush

public static object GetPropertyValue(object container, string propName, out bool exist)
        {
            exist = false;
            object value = null;
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (string.IsNullOrEmpty(propName))
            {
                throw new ArgumentNullException("propName");
            }
            if (Utility.IsInteger(propName))
            {
                #region 索引值部分
                //属性名只为数字.则取数组索引
                int index = Utility.ConverToInt32(propName);
                if (container is IList)
                {
                    IList iList = (IList)container;
                    if (iList.Count > index)
                    {
                        exist = true;
                        value = iList[index];
                    }
                }
                else if (container is ICollection)
                {
                    ICollection ic = (ICollection)container;
                    if (ic.Count > index)
                    {
                        exist = true;
                        IEnumerator ie = ic.GetEnumerator();
                        int i = 0;
                        while (i++ <= index) { ie.MoveNext(); }
                        value = ie.Current;
                    }
                }
                else
                {
                    //判断是否含有索引属性
                    PropertyInfo item = container.GetType().GetProperty("Item", new Type[] { typeof(int) });
                    if (item != null)
                    {
                        try
                        {
                            value = item.GetValue(container, new object[] { index });
                            exist = true;
                        }
                        catch
                        {
                            exist = false;
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region 字段/属性/键值
                //容器是类型.则查找静态属性或字段
                Type type = container is Type ? (Type)container : container.GetType();
                BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase;
                if (!(container is Type)) flags |= BindingFlags.Instance;

                //查找字段
                FieldInfo field = type.GetField(propName, flags);
                if (field != null)
                {
                    exist = true;
                    value = field.GetValue(container);
                }
                else
                {
                    //查找属性
                    PropertyInfo property = type.GetProperty(propName, flags, null, null, Type.EmptyTypes, new ParameterModifier[0]);
                    if (property != null)
                    {
                        exist = true;
                        value = property.GetValue(container, null);
                    }
                    else if (container is ICustomTypeDescriptor)
                    {
                        //已实现ICustomTypeDescriptor接口
                        ICustomTypeDescriptor ictd = (ICustomTypeDescriptor)container;
                        PropertyDescriptor descriptor = ictd.GetProperties().Find(propName, true);
                        if (descriptor != null)
                        {
                            exist = true;
                            value = descriptor.GetValue(container);
                        }
                    }
                    else if (container is IDictionary)
                    {
                        //是IDictionary集合
                        IDictionary idic = (IDictionary)container;
                        if (idic.Contains(propName))
                        {
                            exist = true;
                            value = idic[propName];
                        }
                    }
                    else if (container is NameObjectCollectionBase)
                    {
                        //是NameObjectCollectionBase派生对象
                        NameObjectCollectionBase nob = (NameObjectCollectionBase)container;

                        //调用私有方法
                        MethodInfo method = nob.GetType().GetMethod("BaseGet", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string) }, new ParameterModifier[] { new ParameterModifier(1) });
                        if (method != null)
                        {
                            value = method.Invoke(container, new object[] { propName });
                            exist = value != null;
                        }
                    }
                    else
                    {
                        //判断是否含有索引属性
                        PropertyInfo item = type.GetProperty("Item", new Type[] { typeof(string) });
                        if (item != null)
                        {
                            try
                            {
                                value = item.GetValue(container, new object[] { propName });
                                exist = true;
                            }
                            catch
                            {
                                exist = false;
                            }
                        }
                    }
                }
                #endregion
            }
            return value;
        }

19 View Source File : ToEnumerableTest.cs
License : Apache License 2.0
Project Creator : akarnokd

[Fact]
        public void NonGeneric()
        {
            IEnumerable en = AsyncEnumerable.Range(1, 5).ToEnumerable();

            var enumerator = en.GetEnumerator();

            for (var i = 1; i <= 5; i++)
            {
                replacedert.True(enumerator.MoveNext());
                replacedert.Equal(i, enumerator.Current);
            }
            replacedert.False(enumerator.MoveNext());

            try
            {
                enumerator.Reset();
                replacedert.False(true, "Should have thrown");
            }
            catch (InvalidOperationException)
            {
                // expected
            }
        }

19 View Source File : Style.cs
License : MIT License
Project Creator : arbelatech

IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable) _styles).GetEnumerator();
        }

19 View Source File : SortedObservableCollectionTests.cs
License : Microsoft Public License
Project Creator : AArnott

[Fact]
	public void GetEnumerator_NonGenericInterface()
	{
		this.collection.Add(3);
		this.collection.Add(5);
		IEnumerable enumerable = this.collection;
		IEnumerator enumerator = enumerable.GetEnumerator();
		replacedert.True(enumerator.MoveNext());
		replacedert.Equal(5, enumerator.Current);
		replacedert.True(enumerator.MoveNext());
		replacedert.Equal(3, enumerator.Current);
		replacedert.False(enumerator.MoveNext());
	}

19 View Source File : OneDReader.cs
License : MIT License
Project Creator : architdate

private Result doDecode(BinaryBitmap image, System.Collections.Hashtable hints)
		{
			int width = image.Width;
			int height = image.Height;
			BitArray row = new BitArray(width);
			
			int middle = height >> 1;
			bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER);
			int rowStep = System.Math.Max(1, height >> (tryHarder?7:4));
			int maxLines;
			if (tryHarder)
			{
				maxLines = height; // Look at the whole image, not just the center
			}
			else
			{
				maxLines = 9; // Nine rows spaced 1/16 apart is roughly the middle half of the image
			}
			
			for (int x = 0; x < maxLines; x++)
			{
				
				// Scanning from the middle out. Determine which row we're looking at next:
				int rowStepsAboveOrBelow = (x + 1) >> 1;
				bool isAbove = (x & 0x01) == 0; // i.e. is x even?
				int rowNumber = middle + rowStep * (isAbove?rowStepsAboveOrBelow:- rowStepsAboveOrBelow);
				if (rowNumber < 0 || rowNumber >= height)
				{
					// Oops, if we run off the top or bottom, stop
					break;
				}
				
				// Estimate black point for this row and load it:
				try
				{
					row = image.getBlackRow(rowNumber, row);
				}
				catch (ReaderException)
				{
					continue;
				}
				
				// While we have the image data in a BitArray, it's fairly cheap to reverse it in place to
				// handle decoding upside down barcodes.
				for (int attempt = 0; attempt < 2; attempt++)
				{
					if (attempt == 1)
					{
						// trying again?
						row.reverse(); // reverse the row and continue
						// This means we will only ever draw result points *once* in the life of this method
						// since we want to avoid drawing the wrong points after flipping the row, and,
						// don't want to clutter with noise from every single row scan -- just the scans
						// that start on the center line.
						if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
						{
							System.Collections.Hashtable newHints = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); // Can't use clone() in J2ME
							System.Collections.IEnumerator hintEnum = hints.Keys.GetEnumerator();
							//UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
							while (hintEnum.MoveNext())
							{
								//UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
								System.Object key = hintEnum.Current;
								if (!key.Equals(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
								{
									newHints[key] = hints[key];
								}
							}
							hints = newHints;
						}
					}
					try
					{
						// Look for a barcode
						Result result = decodeRow(rowNumber, row, hints);
						// We found our barcode
						if (attempt == 1)
						{
							// But it was upside down, so note that
							result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object) 180);
							// And remember to flip the result points horizontally.
							ResultPoint[] points = result.ResultPoints;
							points[0] = new ResultPoint(width - points[0].X - 1, points[0].Y);
							points[1] = new ResultPoint(width - points[1].X - 1, points[1].Y);
						}
						return result;
					}
					catch (ReaderException)
					{
						// continue -- just couldn't decode this row
					}
				}
			}
			
			throw ReaderException.Instance;
		}

19 View Source File : CollectionWrapper.cs
License : MIT License
Project Creator : akaskela

IEnumerator IEnumerable.GetEnumerator()
        {
            if (_genericCollection != null)
            {
                return _genericCollection.GetEnumerator();
            }
            else
            {
                return _list.GetEnumerator();
            }
        }

19 View Source File : WorkerOptions.cs
License : MIT License
Project Creator : arcus-azure

IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable) Services).GetEnumerator();
        }

19 View Source File : CrmEntityDataBoundControl.cs
License : MIT License
Project Creator : Adoxio

protected object GetDataObject(IEnumerable data)
		{
			if (data == null)
			{
				return null;
			}
			
			var enumerator = data.GetEnumerator();

			if (!enumerator.MoveNext())
			{
				return null;
			}

			if (enumerator.Current is CrmSiteMapNode)
			{
				return (enumerator.Current as CrmSiteMapNode).Enreplacedy;
			}

			return enumerator.Current;
		}

19 View Source File : JsonLocaleProvider.cs
License : GNU General Public License v3.0
Project Creator : Artentus

IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_locales).GetEnumerator();

19 View Source File : ReadOnlyListWrapper.cs
License : MIT License
Project Creator : alexshtf

IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable) list).GetEnumerator();

19 View Source File : TMapJsonConverter.cs
License : MIT License
Project Creator : atenfyr

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            ICollection keys = ((IOrderedDictionary)value).Keys;
            ICollection values = ((IOrderedDictionary)value).Values;
            IEnumerator valueEnumerator = values.GetEnumerator();

            writer.WriteStartArray();
            foreach (object key in keys)
            {
                valueEnumerator.MoveNext();

                writer.WriteStartArray();
                serializer.Serialize(writer, key);
                serializer.Serialize(writer, valueEnumerator.Current);
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
        }

19 View Source File : JsonData.cs
License : MIT License
Project Creator : 404Lcc

IEnumerator IEnumerable.GetEnumerator ()
        {
            return EnsureCollection ().GetEnumerator ();
        }

19 View Source File : EfDbBase.cs
License : MIT License
Project Creator : Avanade

public void With<T>(T with, Action action)
        {
            if (Comparer<T>.Default.Compare(with, default) != 0 && Comparer<T>.Default.Compare(with, default) != 0)
            {
                if (!(with is string) && with is System.Collections.IEnumerable ie && !ie.GetEnumerator().MoveNext())
                    return;

                action?.Invoke();
            }
        }

19 View Source File : CollectionFormatter.cs
License : Apache License 2.0
Project Creator : allenai

public void Serialize(ref MessagePackWriter writer, IEnumerable value, MessagePackSerializerOptions options)
        {
            if (value == null)
            {
                writer.WriteNil();
                return;
            }

            IMessagePackFormatter<object> formatter = options.Resolver.GetFormatterWithVerify<object>();

            using (var scratchRental = SequencePool.Shared.Rent())
            {
                var scratch = scratchRental.Value;
                MessagePackWriter scratchWriter = writer.Clone(scratch);
                var count = 0;
                var e = value.GetEnumerator();
                try
                {
                    while (e.MoveNext())
                    {
                        writer.CancellationToken.ThrowIfCancellationRequested();
                        count++;
                        formatter.Serialize(ref scratchWriter, e.Current, options);
                    }
                }
                finally
                {
                    if (e is IDisposable d)
                    {
                        d.Dispose();
                    }
                }

                scratchWriter.Flush();
                writer.WriteArrayHeader(count);
                writer.WriteRaw(scratch.AsReadOnlySequence);
            }
        }

19 View Source File : ProgressIndicator.cs
License : MIT License
Project Creator : Adoxio

protected int RenderTypeProgressBar(IEnumerable dataSource)
		{
			var count = 0;
			var progressIndex = 0;
			var clreplacedName = "progress";
			var controlContainer = new HtmlGenericControl("div");
			
			var e = dataSource.GetEnumerator();

			if (string.IsNullOrWhiteSpace(Position))
			{
				CssClreplaced = string.Join(" ", CssClreplaced, clreplacedName);
			}
			else
			{
				switch (Position.ToLowerInvariant())
				{
					case "top":
						clreplacedName += " top";
						break;
					case "bottom":
						clreplacedName += " bottom";
						break;
					case "left":
						clreplacedName += " left";
						CssClreplaced += " col-sm-3 col-md-2";
						break;
					case "right":
						clreplacedName += " right";
						CssClreplaced += " col-sm-3 col-sm-push-9 col-md-2 col-md-push-10";
						break;
				}

				CssClreplaced = string.Join(" ", CssClreplaced, clreplacedName);
			}

			while (e.MoveNext())
			{
				if (e.Current == null)
				{
					continue;
				}

				var indexValue = DataBinder.GetPropertyValue(e.Current, IndexDataPropertyName);
				var activeValue = DataBinder.GetPropertyValue(e.Current, ActiveDataPropertyName);
				var index = Convert.ToInt32(indexValue);
				var active = Convert.ToBoolean(activeValue);
				
				if (active)
				{
					if (ZeroBasedIndex)
					{
						index++;
					}

					progressIndex = index > 0 ? index - 1 : 0;
				}
				
				count++;
			}

			controlContainer.Attributes["clreplaced"] = "bar progress-bar";

			double percent = 0;

			if (count > 0)
			{
				if (!CountLastStepInProgress)
				{
					percent = (double)(progressIndex * 100) / (count - 1);
				}
				else
				{
					percent = (double)(progressIndex * 100) / count;
				}
			}

			var progress = Math.Floor(percent);

			controlContainer.Attributes["style"] = string.Format("width: {0}%;", progress);
			controlContainer.Attributes["role"] = "progressbar";
			controlContainer.Attributes["aria-valuemin"] = "0";
			controlContainer.Attributes["aria-valuemax"] = "100";
			controlContainer.Attributes["aria-valuenow"] = progress.ToString(CultureInfo.InvariantCulture);

			if (progress.CompareTo(0) == 0)
			{
				controlContainer.Attributes["clreplaced"] = controlContainer.Attributes["clreplaced"] + " zero";
			}

			controlContainer.InnerHtml = string.Format("{0}%", progress);

			Controls.Add(controlContainer);

			return count;
		}

19 View Source File : ListSnapshot.cs
License : MIT License
Project Creator : 0x0ade

IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable) List).GetEnumerator();
        }

19 View Source File : Amf3Object.cs
License : MIT License
Project Creator : a1q123456

public IEnumerator GetEnumerator()
        {
            return ((IEnumerable)Fields).GetEnumerator();
        }

19 View Source File : Diagnostics.cs
License : MIT License
Project Creator : adamant

IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)items).GetEnumerator();
        }

19 View Source File : CollectionBase.cs
License : Mozilla Public License 2.0
Project Creator : ahyahy

public virtual System.Collections.IEnumerator GetEnumerator()
        {
            Enumerator = List.GetEnumerator();
            return (System.Collections.IEnumerator)this;
        }

19 View Source File : Logger.cs
License : Apache License 2.0
Project Creator : apache

[Test]
		public void TestAppender1()
		{
			log = (Logger)Utils.GetLogger("test").Logger;
			CountingAppender a1 = new CountingAppender();
			a1.Name = "testAppender1";
			log.AddAppender(a1);

			IEnumerator enumAppenders = ((IEnumerable)log.Appenders).GetEnumerator();
			replacedert.IsTrue(enumAppenders.MoveNext());
			CountingAppender aHat = (CountingAppender)enumAppenders.Current;
			replacedert.AreEqual(a1, aHat);
		}

See More Examples