public void Run() { dynamic expando = new ExpandoObject(); expando.Message = "Hello from the dynamic world"; expando.Print = (Action<string>)((message) => Console.WriteLine("Yea " + message)); Console.WriteLine(expando.Message); expando.Print("Howdy!"); }
private static void DynamicallyAddingExpandoObjectBehavior() { dynamic customer = new ExpandoObject(); customer.Print = (Action)(() => { WriteLine("\nCUSTOMER PROPERTIES"); foreach (var item in customer) { WriteLine($"{item.Key,-20} : {item.Value,20}"); } }); customer.Count = (Func<int>)(() => { var c = (IDictionary<string, object>)customer; return c.Count; }); EnterPropertiesToDynamicType(customer); customer.Print(); WriteLine($"Total property count: {customer.Count()}"); }