public void TestMethodDispatcherWithSingleMethod() { var obj = new Elephant(); var dispatcher = new MethodDispatcher(); dispatcher.AddMethod( typeof(Elephant).Methods( "Eat" ).First() ); dispatcher.Invoke( obj, true, new {} ); Assert.AreEqual( 1, obj.MethodInvoked ); }
public void TestMethodDispatcherWithMultipleMethods() { var obj = new Elephant(); var dispatcher = new MethodDispatcher(); typeof(Elephant).Methods( Flags.InstanceAnyVisibility | Flags.ExcludeBackingMembers ).ForEach( dispatcher.AddMethod ); dispatcher.Invoke( obj, true, new {} ); Assert.AreEqual( 1, obj.MethodInvoked ); dispatcher.Invoke( obj, true, new { count=2.0, food="hay", isHay=true } ); Assert.AreEqual( 5, obj.MethodInvoked ); dispatcher.Invoke( obj, true, new { count=2, volume=4 } ); Assert.AreEqual( 11, obj.MethodInvoked ); }
public void TestMethodDispatcherWithStaticMethods() { var type = typeof(StaticElephant); var dispatcher = new MethodDispatcher(); typeof(StaticElephant).Methods( Flags.StaticAnyVisibility ).ForEach( dispatcher.AddMethod ); dispatcher.Invoke( type, true, new {} ); Assert.AreEqual( 1, StaticElephant.MethodInvoked ); dispatcher.Invoke( type, true, new { count=2.0, food="hay", isHay=true } ); Assert.AreEqual( 5, StaticElephant.MethodInvoked ); dispatcher.Invoke( type, false, new { count=2, volume=4 } ); Assert.AreEqual( 3, StaticElephant.MethodInvoked ); }