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);
        }
        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);
        }
Example #3
0
        /// <summary>
        /// Use the supplied XmlNode to configure the target object. This configuration target
        /// performs a method callback on the target object, and uses the attributes of the XmlNode
        /// as parameters. The method parameter names must match the names of the node attributes
        /// (a leading underscore will be stripped to permit using C# reserved words in the XML file).
        /// This method does not check whether the node matches the requested environment.
        /// </summary>
        /// <param name="target">The object to cofigure.</param>
        /// <param name="node">The node containing the configuration value(s).</param>
        public override void Configure(object target, XmlNode node)
        {
            Hashtable parameters = ExtractAttributes(node);

            parameters.Add("$$content$$", node.Value);
            dispatcher.Invoke(target, parameters);
        }
        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);
        }
Example #5
0
        /// <summary>
        /// Use the supplied XmlNode to configure the target object. This configuration target
        /// performs a method callback on the target object, and uses the attributes of the XmlNode
        /// as parameters. The method parameter names must match the names of the node attributes
        /// (a leading underscore will be stripped to permit using C# reserved words in the XML file).
        /// This method does not check whether the node matches the requested environment.
        /// </summary>
        /// <param name="target">The object to cofigure.</param>
        /// <param name="node">The node containing the configuration value(s).</param>
        public override void Configure(object target, XmlNode node)
        {
            Hashtable parameters = ExtractAttributes(node);

            dispatcher.Invoke(target, parameters);
        }