Пример #1
0
    public async Task Run()
    {
        using var yetAnotherTokenSource = new CancellationTokenSource();
        var custom = new CustomEnumerable(yetAnotherTokenSource);

        await foreach (var delay in custom
                       .WithCancellation(yetAnotherTokenSource.Token)
                       .ConfigureAwait(false))
        {
            Console.WriteLine($"await Task.Delay({delay})");

            await Task.Delay(delay)
            .ConfigureAwait(false);
        }

        custom = new CustomEnumerable(yetAnotherTokenSource);
        await foreach (var delay in custom)
        {
            Console.WriteLine($"await Task.Delay({delay})");

            await Task.Delay(delay)
            .ConfigureAwait(false);
        }
    }
        public void VerifyIndexOfBehavior()
        {
            RunOnUIThread.Execute(() =>
            {
                var collections = new List <IEnumerable>();
                collections.Add(new ObservableVectorWithUniqueIds(Enumerable.Range(0, 10)));
                collections.Add(new ObservableCollection <int>(Enumerable.Range(0, 10)));

                foreach (var collection in collections)
                {
                    var dataSource = new ItemsSourceView(collection);
                    foreach (int i in collection)
                    {
                        Verify.AreEqual(i, dataSource.IndexOf(i));
                    }

                    Verify.AreEqual(-1, dataSource.IndexOf(11));
                }

                // Enumerabl.Range returns IEnumerable which does not provide IndexOf
                var testingItemsSourceView = new ItemsSourceView(Enumerable.Range(0, 10));

                /*var index = -1;
                 * try
                 * {
                 *  index = testingItemsSourceView.IndexOf(0);
                 * }catch(Exception){ }
                 * Verify.AreEqual(-1, index);*/


                var nullContainingEnumerable = new CustomEnumerable();
                testingItemsSourceView       = new ItemsSourceView(nullContainingEnumerable);

                Verify.AreEqual(1, testingItemsSourceView.IndexOf(null));
            });
        }
Пример #3
0
        static void Main(string[] args)
        {
            List <Entity> entities = new List <Entity>();

            entities.Add(new Entity()
            {
                Id = 1
            });

            List <Company> companies = new List <Company>();

            companies.Add(new Company()
            {
                Id = 2, Name = "Ford"
            });

            Get(entities);
            Get(companies);


            ICustomEnumerable <Entity> entities1 = new CustomEnumerable <Entity>();

            entities.Add(new Entity()
            {
                Id = 1
            });

            ICustomEnumerable <Company> companies1 = new CustomEnumerable <Company>();

            companies.Add(new Company()
            {
                Id = 2, Name = "Ford"
            });

            entities1 = companies1;
        }
 private CustomEnumerable(T value, CustomEnumerable <T> next)
 {
     this.value = value;
     this.next  = next;
     count      = this.next.count + 1;
 }
Пример #5
0
 public ContainerWithReadOnlyCustomEnumerable()
 {
     Items = new CustomEnumerable();
 }