[TestClass]
public class UnitTest1
{
//DbContext DbContext = DbContext.GetInstance("Provider=microsoft.jet.oledb.4.0;data source='d:/wwwroot/wzxinchen/databases/xinchenDB.mdb'", "System.Data.OleDb");
string method = "GET";
string[] parameters;
public string[] Parameters
{
get { return parameters; }
set { parameters = value; }
}
ParameterInfo[] pis;
string controller = "Board";
string action = "Child";
string path = "/bbs";
[TestMethod]
public void Action()
{
BoardController c = new BoardController();
c.Child(11);
}
[TestMethod]
public void ReflectAction()
{
this.parameters = new string[2];
Controller controller = (Controller)ClassHelper.getClass("Xinchen.WebSite", "Controllers.bbs.BoardController");
Type controllerType = controller.GetType();
ControllerContext controllerContext = new ControllerContext(controller, new ControllerValuePair(this.controller, this.action, this.path));
ControllerContext.Current = controllerContext;
MethodInfo mi = ClassHelper.GetMethod(controllerType, action);
ActionResult actionResult = (ActionResult)mi.Invoke(controller, new object[2] { 11, 1 });
}
}
以上是测试代码,使用的vs的单元测试
Action方法用了500毫秒
ReflectAction方法居然只用了5毫秒
这到底是为什么?不是说反射很慢吗?
------解决方案--------------------