public static void ExpandoTest() { dynamic sampleObject = new ExpandoObject(); //Adding New Members sampleObject.test = "Dynamic Property"; Console.WriteLine(sampleObject.test); Console.WriteLine(sampleObject.test.GetType()); // This code example produces the following output: // Dynamic Property // System.String sampleObject.number = 10; sampleObject.Increment = (Action)(() => { sampleObject.number++; }); // Before calling the Increment method. Console.WriteLine(sampleObject.number); sampleObject.Increment(); // After calling the Increment method. Console.WriteLine(sampleObject.number); // This code example produces the following output: // 10 // 11 }
public static void ExpandoDemo() { dynamic ex = new ExpandoObject(); ex.Name = "Keith"; ex.Age = "pi"; Console.WriteLine(new { ex.Name, ex.Age, ex.ShirtColor }); ex.Increment = new Func<int, int>(i => i + 1); Console.WriteLine("1 + 1 = {0}", ex.Increment(1)); }
public void ExpandoObjectDemo() { dynamic dyn = new ExpandoObject(); dyn.number = 1; dyn.Increment = new Action(() => { dyn.number++; }); Console.WriteLine(dyn.number); dyn.Increment(); Console.WriteLine(dyn.number); foreach (var propery in (IDictionary<string, object>)dyn) { Console.WriteLine(propery.Key+":"+propery.Value); } ((INotifyPropertyChanged)dyn).PropertyChanged += DynamicDemo_PropertyChanged; dyn.name = "changed"; dyn.name = "another"; }
public static void Expando() { dynamic ex = new ExpandoObject(); ex.Name = "Keith"; Console.WriteLine(ex.Name); ex.Increment = new Func<int, int>(i => i + 1); Console.WriteLine("1 + 1 = {0}", ex.Increment(1)); }