public void ShouldBeAbleToAddExtensionMethodsIntoDynamicObjects() { var dynamicObject = new DynamicObject(new RubberDucky()); dynamicObject.AddExtensionClass(typeof(SampleExtensionMethods)); dynamic expando = dynamicObject.AsExpandoObject(); SampleExtensionMethods.ResetCallCounter(); int result = expando.IncrementCounter(); Assert.AreEqual(1, result); }
public void ShouldBeAbleToUseCLRDynamicObjectsAsExpandoObjects() { Func <object[], object> body = args => 42; var dynamicObject = new DynamicObject(new object()); dynamicObject.AddMethod("GetFoo", body, typeof(int)); dynamic expando = dynamicObject.AsExpandoObject(); int result = expando.GetFoo(); Assert.AreEqual(42, result); }