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


C# List.Cast方法代码示例

本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# List.Cast方法的具体用法?C# List.Cast怎么用?C# List.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualStudio.TestTools.UnitTesting.List的用法示例。


在下文中一共展示了List.Cast方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WorkbookInsert

        public void WorkbookInsert()
        {
            List<SumAnalysisX> SumAnalysisXs = new List<SumAnalysisX>();

            for (int i = 0; i < 8; i++)
            {
                SumAnalysisX SumAnalysisX1 = new SumAnalysisX() { ClassName = i.ToString() + "班级", MaxScore = 100 + i, Total = 1000 + i, TotalAverage = 10 + i };

                List<SubjectScoreDetailX> ssd = new List<SubjectScoreDetailX>();

                for (int j = 0; j < 4; j++)
                {
                    ssd.Add(new SubjectScoreDetailX() { Score = 10000 + j, TypeName = "kemu " + j.ToString(), TypeId = j });
                }

                SumAnalysisX1.SubjectScoreDetails = ssd;

                SumAnalysisXs.Add(SumAnalysisX1);

            }

            WorkbookWrapper w = new WorkbookWrapper();

            SheetDetail sd = new SheetDetail("sxf");

            SheetDetailDataWrapper sheetDetailDataWrapper = new SheetDetailDataWrapper("No.1", SumAnalysisXs.Cast<IExcelModelBase>());

            sd.SheetDetailDataWrappers.Add(sheetDetailDataWrapper);

            w.AddSheetDetail(sd);

            w.Save(@"C:\sxf.xls");
        }
开发者ID:dut3062796s,项目名称:ExcelHelper,代码行数:33,代码来源:WorkbookTest.cs

示例2: ExpandoAsJoin

        public void ExpandoAsJoin()
        {
            var customers = new List<dynamic>();
            for (int i = 0; i < 10; ++i)
            {
                string iter = i.ToString();
                for (int j = 0; j < 3; ++j)
                {
                    dynamic customer = new ExpandoObject();
                    customer.City = "Chicago" + iter;
                    customer.Id = i;
                    customer.Name = "Name" + iter;
                    customer.CompanyName = "Company" + iter + j.ToString();

                    customers.Add(customer);
                }
            }

            var customers2 = new List<dynamic>(customers);

            var result = customers2.Cast<IDictionary<string, object>>().Query<IDictionary<string, object>, IDictionary<string, object>, dynamic>("SELECT this.City FROM this INNER JOIN that ON this.Id = that.Id", customers.Cast<IDictionary<string, object>>());

            var answer = from c2 in customers2
                         join c in customers on c2.Id equals c.Id
                         select c2.City;

            Assert.IsTrue(result.Any());
            Assert.IsTrue(answer.SequenceEqual(result));
        }
开发者ID:purnachandrapilla,项目名称:SqlLinq,代码行数:29,代码来源:DynamicTests.cs

示例3: All

        public void All()
        {
            var e1 = Emit<LotsOfParams>.NewDynamicMethod();

            for (ushort i = 0; i < 260; i++)
            {
                e1.LoadArgumentAddress(i);
                e1.LoadIndirect<int>();
            }

            for (var i = 0; i < 259; i++)
            {
                e1.Add();
            }

            e1.Return();

            var d1 = e1.CreateDelegate();

            var rand = new Random();
            var args = new List<int>();
            for (var i = 0; i < 260; i++)
            {
                args.Add(rand.Next(10));
            }

            var ret = (int)d1.DynamicInvoke(args.Cast<object>().ToArray());

            Assert.AreEqual(args.Sum(), ret);
        }
开发者ID:JasonPunyon,项目名称:Sigil,代码行数:30,代码来源:LoadArgumentAddress.cs

示例4: ThenNextMustUpdateDependentIterators

        public void ThenNextMustUpdateDependentIterators()
        {
            var sources = new List<TestSource>
            {
                new TestSource{ Count = 0 },
                new TestSource{ Count = 100 }
            };

            using (var first = new Iterator(sources.Cast<object>().ToList(), null))
            using (var second = new Iterator(new List<object>{first}, null))
            {
                Assert.AreEqual(0, ((IList<object>)first.GetItem())[0]);
                Assert.AreEqual(100, ((IList<object>)first.GetItem())[1]);

                Assert.AreEqual(0, ((IList<object>)second.GetItem())[0]);
                Assert.AreEqual(100, ((IList<object>)second.GetItem())[1]);

                Iterator.NextAll(Iterator.DefaultScope);

                Assert.AreEqual(1, ((IList<object>)first.GetItem())[0]);
                Assert.AreEqual(101, ((IList<object>)first.GetItem())[1]);

                Assert.AreEqual(1, ((IList<object>)second.GetItem())[0]);
                Assert.AreEqual(101, ((IList<object>)second.GetItem())[1]);
            }
        }
开发者ID:geoffles,项目名称:Foobricator,代码行数:26,代码来源:WhenUsingAnIterator.cs

示例5: All

        public void All()
        {
            var e1 = Emit<LotsOfParams>.NewDynamicMethod();

            var args = new List<int>();

            for (ushort i = 0; i < 260; i++)
            {
                e1.LoadConstant(i);
                e1.StoreArgument(i);

                args.Add(i);
            }

            for (ushort i = 0; i < 260; i++)
            {
                e1.LoadArgument(i);
            }

            for (var i = 0; i < 259; i++)
            {
                e1.Add();
            }

            e1.Return();

            var d1 = e1.CreateDelegate();

            var x = (int)d1.DynamicInvoke(args.Cast<object>().ToArray());

            Assert.AreEqual(args.Sum(), x);
        }
开发者ID:zhuozhuowang,项目名称:Sigil,代码行数:32,代码来源:StoreArgument.cs

示例6: AllNonGeneric

        public void AllNonGeneric()
        {
            var returnType = typeof(LotsOfParams).GetMethod("Invoke").ReturnType;
            var paramTypes = typeof(LotsOfParams).GetMethod("Invoke").GetParameters().Select(p => p.ParameterType).ToArray();

            var e1 = Emit.NewDynamicMethod(returnType, paramTypes);

            var args = new List<int>();

            for (ushort i = 0; i < 260; i++)
            {
                e1.LoadConstant(i);
                e1.StoreArgument(i);

                args.Add(i);
            }

            for (ushort i = 0; i < 260; i++)
            {
                e1.LoadArgument(i);
            }

            for (var i = 0; i < 259; i++)
            {
                e1.Add();
            }

            e1.Return();

            var d1 = e1.CreateDelegate<LotsOfParams>();

            var x = (int)d1.DynamicInvoke(args.Cast<object>().ToArray());

            Assert.AreEqual(args.Sum(), x);
        }
开发者ID:zhuozhuowang,项目名称:Sigil,代码行数:35,代码来源:StoreArgument.NonGeneric.cs

示例7: ThenGetItemMustNotNext

        public void ThenGetItemMustNotNext()
        {
            var sources = new List<TestSource>
            {
                new TestSource{ Count = 0 },
                new TestSource{ Count = 100 }
            };

            using (var iterator = new Iterator(sources.Cast<object>().ToList(), null))
            {
                //Incremented on next due to constructor
                Assert.AreEqual(1, sources[0].Count);
                Assert.AreEqual(101, sources[1].Count);

                Assert.AreEqual(0, ((IList<object>)iterator.GetItem())[0]);
                Assert.AreEqual(100, ((IList<object>)iterator.GetItem())[1]);

                //Test again to make sure it doesn't pull
                Assert.AreEqual(0, ((IList<object>)iterator.GetItem())[0]);
                Assert.AreEqual(100, ((IList<object>)iterator.GetItem())[1]);
            }
        }
开发者ID:geoffles,项目名称:Foobricator,代码行数:22,代码来源:WhenUsingAnIterator.cs

示例8: ExpandoAsDistinct

        public void ExpandoAsDistinct()
        {
            var source = new List<dynamic>();
            for (int i = 0; i < 10; ++i)
            {
                string iter = i.ToString();
                for (int j = 0; j < 3; ++j)
                {
                    dynamic customer = new ExpandoObject();
                    customer.City = "Chicago" + iter;
                    customer.Id = i;
                    customer.Name = "Name" + iter;
                    customer.CompanyName = "Company" + iter + j.ToString();

                    source.Add(customer);
                }
            }
            var result = source.Cast<IDictionary<string, object>>().Query<IDictionary<string, object>, dynamic>("SELECT DISTINCT City, Name FROM this").Cast<IDictionary<string, object>>();

            var answer = source.Select(d => { dynamic o = new ExpandoObject(); o.City = d.City; o.Name = d.Name; return o; }).Cast<IDictionary<string, object>>().Distinct(new DictionaryComparer<string, object>());

            Assert.IsTrue(result.Any());
            Assert.IsTrue(answer.SequenceEqual(result, new DictionaryComparer<string, object>()));
        }
开发者ID:purnachandrapilla,项目名称:SqlLinq,代码行数:24,代码来源:DistinctTests.cs

示例9: ExpandoAsSource

        public void ExpandoAsSource()
        {
            var customers = new List<dynamic>();
            for (int i = 0; i < 10; ++i)
            {
                string iter = i.ToString();
                for (int j = 0; j < 3; ++j)
                {
                    dynamic customer = new ExpandoObject();
                    customer.City = "Chicago" + iter;
                    customer.Id = i;
                    customer.Name = "Name" + iter;
                    customer.CompanyName = "Company" + iter + j.ToString();

                    customers.Add(customer);
                }
            }

            // all this casting is just to get the answer and result into the same storage types for comparison
            var result = customers.Cast<IDictionary<string, object>>().Query<IDictionary<string, object>, dynamic>("SELECT City, Name FROM this").Cast<IDictionary<string, object>>();
            var answer = customers.Select<dynamic, dynamic>(d => { dynamic o = new ExpandoObject(); o.City = d.City; o.Name = d.Name; return o; }).Cast<IDictionary<string, object>>();

            Assert.IsTrue(result.Any());
            Assert.IsTrue(answer.SequenceEqual(result, new DictionaryComparer<string, object>()));
        }
开发者ID:purnachandrapilla,项目名称:SqlLinq,代码行数:25,代码来源:DynamicTests.cs

示例10: ThenNextMustUpdateFromSources

        public void ThenNextMustUpdateFromSources()
        {
            var sources = new List<TestSource>
            {
                new TestSource{ Count = 0 },
                new TestSource{ Count = 100 }
            };

            using (var iterator = new Iterator(sources.Cast<object>().ToList(),null))
            {
                //Incremented on next due to constructor
                Assert.AreEqual(1, sources[0].Count);
                Assert.AreEqual(101, sources[1].Count);

                Assert.AreEqual(0, ((IList<object>)iterator.GetItem())[0] );
                Assert.AreEqual(100, ((IList<object>)iterator.GetItem())[1]);

                Iterator.NextAll(Iterator.DefaultScope);

                Assert.AreEqual(2, sources[0].Count);
                Assert.AreEqual(102, sources[1].Count);

                Assert.AreEqual(1, ((IList<object>)iterator.GetItem())[0]);
                Assert.AreEqual(101, ((IList<object>)iterator.GetItem())[1]);
            }
        }
开发者ID:geoffles,项目名称:Foobricator,代码行数:26,代码来源:WhenUsingAnIterator.cs

示例11: GivenInitialRecords_WhenBind_ThenResultTotalRecordsMatches

        public void GivenInitialRecords_WhenBind_ThenResultTotalRecordsMatches()
        {
            IQueryable<Program> originalItems = new List<Program> { new Program(), new Program(), new Program() }.AsQueryable();
            IQueryable<Program> sortedItems = new List<Program>().AsQueryable().OrderBy(p => p);
            DataTable.Expect(m => m.ApplySort(null)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Cast<object>().ToList());

            DataTableResultModel actual = Target.Bind<Program>(originalItems, DataTable, RequestModel);

            Assert.AreEqual(originalItems.Count(), actual.iTotalRecords);
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:11,代码来源:DataTableBinderTest.cs

示例12: WhenBind_ThenApplyFilter_AndThenApplySort_AndThenCreateResultSet

        public void WhenBind_ThenApplyFilter_AndThenApplySort_AndThenCreateResultSet()
        {
            IQueryable<Program> originalItems = Enumerable.Empty<Program>().AsQueryable();
            IQueryable<Program> filteredItems = new List<Program>().AsQueryable();
            IOrderedQueryable<Program> sortedItems = new List<Program>().AsQueryable().OrderBy(p => p);
            DataTable.Expect(m => m.ApplyFilters(originalItems)).Return(filteredItems);
            DataTable.Expect(m => m.ApplySort(filteredItems)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Cast<object>().ToList());

            Target.Bind<Program>(originalItems, DataTable, RequestModel);

            DataTable.AssertWasCalled(m => m.CreateResultSet(sortedItems, RequestModel));
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:13,代码来源:DataTableBinderTest.cs

示例13: GivenRequestEchoValue_WhenBind_ThenResultEchoMatches

        public void GivenRequestEchoValue_WhenBind_ThenResultEchoMatches()
        {
            string expected = "this is the expected!";
            IQueryable<Program> items = Enumerable.Empty<Program>().AsQueryable();
            IQueryable<Program> sortedItems = new List<Program>().AsQueryable().OrderBy(p => p);
            RequestModel.sEcho = expected;
            DataTable.Expect(m => m.ApplySort(null)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Cast<object>().ToList());

            DataTableResultModel actual = Target.Bind<Program>(items, DataTable, RequestModel);

            Assert.AreEqual(expected, actual.sEcho);
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:13,代码来源:DataTableBinderTest.cs

示例14: Cast

        public void Cast()
        {
            // arrange
            List<Object> list = new List<Object>() { 1, 2, 3 };

            // act
            List<int> actual = list.Cast<int>().ToList();

            // assert
            Assert.AreEqual(1, actual[0]);
            Assert.AreEqual(2, actual[1]);
            Assert.AreEqual(3, actual[2]);
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:13,代码来源:EnumerableTest.cs


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