示例#1
0
 IEnumerator <T> RetainEnumerator()
 {
     if (enumerator == null)
     {
         enumerator           = new CustomEnumerator(this);
         isEnumeratorRetained = true;
         return(enumerator);
     }
     else
     {
         if (isEnumeratorRetained)
         {
             // sorry, this.enumerator is retained,
             // so would produce base enumerator
             return(base.GetEnumerator());
         }
         else
         {
             // not retained, so will just return an instance
             isEnumeratorRetained = true;
             // reset it with special public method
             enumerator.MyReset();
             return(enumerator);
         }
     }
 }
示例#2
0
 void ReleaseEnumerator(CustomEnumerator enumerator)
 {
     if (ReferenceEquals(enumerator, this.enumerator))
     {
         // the reference equals, so it is ok to release
         isEnumeratorRetained = false;
     }
 }
示例#3
0
文件: Program.cs 项目: Ahura007/loop
        static void Main(string[] args)
        {
            var           someData = Enumerable.Range(0, 1000000000).ToList();
            StringBuilder sb       = new StringBuilder();

            sb.Append("for Property             " + For.Property(someData) + Environment.NewLine);
            sb.Append("for Variable             " + For.Variable(someData.Count) + Environment.NewLine);

            sb.Append("parallel For Property    " + ParallelFor.Property(someData) + Environment.NewLine);
            sb.Append("parallel For Variable    " + ParallelFor.Variable(someData.Count) + Environment.NewLine);

            sb.Append("while Variable           " + While.Variable(someData.Count) + Environment.NewLine);
            sb.Append("while Property           " + While.Property(someData) + Environment.NewLine);

            sb.Append("do While Variable        " + DoWhile.Variable(someData.Count) + Environment.NewLine);
            sb.Append("do While Property        " + DoWhile.Property(someData) + Environment.NewLine);

            sb.Append("foreach A                " + Foreach.Test(someData) + Environment.NewLine);
            sb.Append("foreach B                " + Foreach.BasicTestOne(someData) + Environment.NewLine);
            sb.Append("foreach C                " + Foreach.BasicTestTwo(someData) + Environment.NewLine);

            sb.Append("parallel Foreach         " + ParallelForEach.Test(someData) + Environment.NewLine);

            sb.Append("foreach Linq A           " + ForeachLinq.Test(someData) + Environment.NewLine);
            sb.Append("foreach Linq B           " + ForeachLinq.BasicForEach(someData) + Environment.NewLine);


            System.IO.File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\loop.txt", sb.ToString());



            //set break point in CustomEnumerator method and debug
            var list = new CustomEnumerator();

            foreach (Person item in list)
            {
            }


            Console.ReadLine();
        }
示例#4
0
        public void SelectPrevPart()
        {
            if (_partEnumerator == null)
            {
                _partEnumerator = Model.Parts.GetCustomEnumerator();
            }
            else
            {
                SelectedPart.Selected = false;
            }

            if (_partEnumerator.MovePrev())
            {
                SelectedPart          = _partEnumerator.Current;
                SelectedPart.Selected = true;
            }
            else
            {
                _partEnumerator = null;
                SelectedPart    = null;
            }
        }
示例#5
0
 public new CustomEnumerator GetEnumerator()
 {
     _enumerator = new CustomEnumerator(base.GetEnumerator(), this);
     return(_enumerator);
 }
示例#6
0
 public new IEnumerator <T> GetEnumerator()
 {
     _enumerator = new CustomEnumerator(base.GetEnumerator());
     return(_enumerator);
 }
示例#7
0
 public CustomEnumerable(IEnumerable <T> source)
 {
     _internalEnumerator = new CustomEnumerator <T>(source.GetEnumerator());
 }