public void IterateOverDynamicPropertiesTest() { var ex = new ExpandoInstance { Name = "Name", Entered = DateTime.Now }; dynamic exd = ex; exd.Company = "Company"; exd.Accesses = 10; // Dictionary pseudo implementation ex["Count"] = 10; ex["Type"] = "MyType"; // Dictionary Count - 2 dynamic props added Assert.IsTrue(ex.Properties.Count == 4); // iterate over all properties foreach (KeyValuePair <string, object> prop in exd.GetProperties(true)) { Trace.WriteLine(prop.Key + " " + prop.Value); } }
public void PropertyAsIndexerTest() { // Set standard properties var ex = new ExpandoInstance { Name = "Name", Entered = DateTime.Now }; Assert.AreEqual(ex.Name, ex["Name"]); Assert.AreEqual(ex.Entered, ex["Entered"]); }
public void DynamicAccessToPropertyTest() { // Set standard properties var ex = new ExpandoInstance { Name = "Name", Entered = DateTime.Now }; // turn into dynamic dynamic exd = ex; // Dynamic can access Assert.AreEqual(ex.Name, exd.Name); Assert.AreEqual(ex.Entered, exd.Entered); }
public void AddAndReadDynamicIndexersTest() { var ex = new ExpandoInstance { Name = "Name", Entered = DateTime.Now }; ex["Address"] = "Address 123"; ex["Contacted"] = true; dynamic exd = ex; Assert.AreEqual(exd.Address, ex["Address"]); Assert.AreEqual(exd.Contacted, true); }
public void MixInObjectInstanceTest() { // Create expando an mix-in second objectInstanceTest var ex = new ExpandoInstance(new Address()) { Name = "Name", Entered = DateTime.Now }; // create dynamic dynamic exd = ex; // values should show Addresses initialized values (not null) Trace.WriteLine(string.Format("address:{0}", exd.FullAddress as string)); Trace.WriteLine(string.Format("email:{0}", exd.Email as string)); Trace.WriteLine(string.Format("phone:{0}", exd.Phone as string)); }
public void IterateOverDynamicPropertiesTest() { var ex = new ExpandoInstance { Name = "Name", Entered = DateTime.Now }; dynamic exd = ex; exd.Company = "Company"; exd.Accesses = 10; // Dictionary pseudo implementation ex["Count"] = 10; ex["Type"] = "MyType"; // Dictionary Count - 2 dynamic props added Assert.IsTrue(ex.Properties.Count == 4); // iterate over all properties foreach (KeyValuePair<string, object> prop in exd.GetProperties(true)) { Trace.WriteLine(prop.Key + " " + prop.Value); } }