Example #1
0
        private static void GroupBy(Model[] source)
        {
            CodeTimeChecker checker = new CodeTimeChecker();

            checker.Set();
            var group1 = source.GroupBy(item => item.Item6);

            checker.Check();
            foreach (var group in group1)
            {
                Console.Write("{0}, ", group.Key);
            }
            Console.WriteLine();

            Console.WriteLine("----------------------");

            checker.Set();
            var group2 = source.GroupBy(new string[] { "Item6" });

            checker.Check();
            foreach (var group in group2)
            {
                Console.Write("{0}, ", group.Key["Item6"]);
            }
            Console.WriteLine();
        }
Example #2
0
        private static void Select(Model[] source)
        {
            CodeTimeChecker checker = new CodeTimeChecker();
            var             result1 = source
                                      .Select(item => new
            {
                item.Item1,
                item.Item3,
                item.Item5
            });

            checker.Set();
            foreach (var item in result1)
            {
                Console.WriteLine("{0}, {1}, {2}", item.Item1, item.Item3, item.Item5);
            }
            checker.Check();

            Console.WriteLine("----------------------");

            var result2 = source
                          .Select(item =>
            {
                dynamic newType = new ExpandoObject();
                ((IDictionary <string, object>)newType)["Item1"] = item.Item1;
                newType.Item3 = item.Item3;
                newType.Item5 = item.Item5;
                return(newType);
            });

            checker.Set();
            foreach (var item in result2)
            {
                Console.WriteLine("{0}, {1}, {2}", item.Item1, item.Item3, item.Item5);
            }
            checker.Check();

            Console.WriteLine("----------------------");

            var result3 = source
                          .Select(item => AnonymousTypeSelector.Create(item.Item1, item.Item3, item.Item5));

            checker.Set();
            foreach (var item in result3)
            {
                Console.WriteLine("{0}, {1}, {2}", item.Item1, item.Item2, item.Item3);
            }
            checker.Check();
        }