Esempio n. 1
0
        public static void Test()
        {
            List <Customer> allCustomers = GetAllCustomers();
            var             result       = allCustomers
                                           .Select(customer => new[]
            {
                customer.FirstName,
                customer.LastName
            }
                                                   .Concat(customer.CreditCards.Select(cc => cc.Name))
                                                   .Concat(customer.Addresses.Select(address => address.Street)));

            foreach (var c in result)
            {
                Console.WriteLine(ChoUtility.ToStringEx(c.ToList().ToExpandoObject()));
            }
            return;

            //  Customer has CreditCards list and Addresses list

            // how to flatten Customer, CreditCards list, and Addresses list into one flattened record/list?

            var flatenned = from c in allCustomers
                            select
                            c.FirstName + ", " +
                            c.LastName + ", " +
                            String.Join(", ", c.CreditCards.Select(c2 => c2.Name).ToArray()) + ", " +
                            String.Join(", ", c.Addresses.Select(a => a.Street).ToArray());

            flatenned.ToList().ForEach(Console.WriteLine);
        }
Esempio n. 2
0
        static void LoadTextTest()
        {
            string txt = "Id, Name\r\n1, Mark";

            foreach (var e in ChoCSVReader.LoadText(txt).WithFirstLineHeader())
            {
                Console.WriteLine(ChoUtility.ToStringEx(e));
            }
        }
Esempio n. 3
0
        static void Sample7()
        {
            using (var jr = new ChoJSONReader <Family>("sample7.json").WithJSONPath("$.fathers"))
            {
                foreach (var x in jr)
                {
                    Console.WriteLine(x.Id);
                    foreach (var fm in x.Daughters)
                    {
                        Console.WriteLine(fm);
                    }
                }
            }
            return;

            using (var jr = new ChoJSONReader("sample7.json").WithJSONPath("$.fathers")
                            .WithField("id")
                            .WithField("married")
                            .WithField("name")
                            .WithField("sons")
                            .WithField("daughters", fieldType: typeof(Dictionary <string, object>[]))
                   )
            {
                foreach (var item in jr)
                {
                    var x = item.id;
                    Console.WriteLine(x.GetType());

                    Console.WriteLine(item.id);
                    Console.WriteLine(item.married);
                    Console.WriteLine(item.name);
                    foreach (dynamic son in item.sons)
                    {
                        var x1 = son.address;
                        //Console.WriteLine(ChoUtility.ToStringEx(son.address.street));
                    }
                    foreach (var daughter in item.daughters)
                    {
                        Console.WriteLine(ChoUtility.ToStringEx(daughter));
                    }
                }
            }
        }
Esempio n. 4
0
        static void QuickPOCOTest()
        {
            //List<EmployeeRecSimple> objs = new List<EmployeeRecSimple>();

            //EmployeeRecSimple rec1 = new EmployeeRecSimple();
            //rec1.Id = null;
            //rec1.Name = "Mark";
            //rec1.Depends = new List<string>() { "AA", "BB" };
            //rec1.Courses = new Dictionary<int, string>() { { 1, "AA" }, { 2, "BB" } };
            //objs.Add(rec1);

            //EmployeeRecSimple rec2 = new EmployeeRecSimple();
            //rec2.Id = "2";
            //rec2.Name = null;
            //objs.Add(rec2);

            //using (var parser = new ChoXmlWriter<EmployeeRecSimple>("Emp.xml").WithXPath("Employees/Employee"))
            //{
            //    parser.Write(objs);
            //}
            //        using (var reader = new ChoXmlReader("emp.xml").WithXPath("Employees/Employee")
            //.WithField("Id")
            //.WithField("Name")
            //.WithField("Depends", isArray: false, fieldType: typeof(List<string>))
            //.WithField("KVP", isArray: false, fieldType: typeof(List<ChoKeyValuePair<int, string>>))
            //)
            //        {
            //            foreach (var i in reader)
            //                Console.WriteLine(ChoUtility.ToStringEx(i));
            //        }

            using (var reader = new ChoXmlReader <EmployeeRecSimple>("emp.xml").WithXPath("Employees/Employee"))
            {
                foreach (var i in reader)
                {
                    Console.WriteLine(ChoUtility.ToStringEx(i));
                }
            }
        }
Esempio n. 5
0
        public override string ToString()
        {
            StringBuilder msg = new StringBuilder(Name.IsNullOrWhiteSpace() ? "ExpandoObject Properties" : "{0} ExpandoObject Properties".FormatString(Name));

            if (_properties != null)
            {
                foreach (string key in _properties.Keys)
                {
                    if (!(_properties[key] is ChoPropertyBag))
                    {
                        msg.AppendFormat("{0}: {1}{2}".FormatString(key, ChoUtility.ToStringEx(_properties[key])));
                    }
                }
                foreach (string key in _properties.Keys)
                {
                    if (_properties[key] is ChoPropertyBag)
                    {
                        msg.AppendFormat("{0}".FormatString(ChoUtility.ToStringEx(_properties[key])));
                    }
                }
            }
            return(msg.ToString());
        }
Esempio n. 6
0
 public string Dump()
 {
     return(ChoUtility.ToStringEx(this));
 }