通过将方法名称存储在XML文件中来绑定方法 [英] bind a method by store the name of method in the XML file

查看:67
本文介绍了通过将方法名称存储在XML文件中来绑定方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题可能会让您感到困惑.好吧,下面我将举一个例子:
首先,我保存一个xml文件进行测试;

The title Maybe make you confused.ok!the following I will show an example:
at first,i save a xml file to test like this;

<behaviorInfo>
<name>tiger</name>
<actionname>play</actionname>
</behaviorInfo>


我希望我的应用程序可以通过读取xml文件来调用我在源文件中定义的名为"play"的方法.当然,我可以更改"actionname"子元素,甚至可以是"eat",应用程序可以更改其自己的行为无需重新编译.

非常感谢您!


I want my application can invoke the method named "play" which I have defined in my source file by reading the xml file.Of course,I can change the "actionname" child element,maybe "eat",the application can change its own behavior not need to be recompiled.

thank you very much!

推荐答案

好吧,考虑到您的应用程序应仅具有编译时已知的方法名,您应该能够解析XML并使用switch语句执行此操作.但是,如果您希望它与将来添加的任何方法配合使用,那么您需要编写代码以使代码使用反射进行自身调用.
Well, given that your application should only have method names that are known to you at compile time, you should be able to parse your XML and use a switch statement to do this. However, if you want it to magically work with any methods that you add in future, then you need to write code that causes your code to call itself using reflection.


这篇关于通过将方法名称存储在XML文件中来绑定方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆