public void GetClassTypeTest1() { ReflectHelper reflectHelper = new ReflectHelper(); reflectHelper.setGlobalNamespace("CourseServer.Controllers"); Type t = reflectHelper.GetClassType("TestController"); Assert.IsNull(t); }
public void GetRouteHandlerTest() { ReflectHelper reflectHelper = new ReflectHelper(); reflectHelper.setGlobalNamespace("CourseServer.Controllers"); reflectHelper.setInsecureReflect(true); RouteHandlerInfo handlerInfo = reflectHelper.GetRouteHandler("Advance.UserManagerController@AllUser"); Assert.AreEqual(typeof(UserManagerController), handlerInfo.Handler); Assert.AreEqual(1, handlerInfo.ParamInfo.Length); //Assert.AreEqual("DoSomething", handlerInfo.Callback.Name); }
public static void Init(Type dbContext, string connectionString, int timeout) { Type requireType = typeof(DbContext); if (!dbContext.IsSubclassOf(requireType)) { Dumper.Log(TAG, "The context of database class must extend from " + requireType.FullName); return; } if (TextUtils.isEmpty(connectionString)) { Dumper.Log(TAG, "Empty connection string."); return; } ReflectHelper reflectHelper = new ReflectHelper(); if (!reflectHelper.HasConstructor(dbContext, new Type[] { typeof(string), typeof(int) })) { Dumper.Log(TAG, "Cannot found the constructor with a string type of argument " + "in the context of database classes " + dbContext.FullName); return; } if (timeout <= 0) { timeout = DEFAULT_TIMEOUT; Dumper.Log(TAG, "Invalid timeout value for the database connection, set up to the default value " + DEFAULT_TIMEOUT); } DbContextHelper.dbContext = dbContext; DbContextHelper.connectionString = connectionString; DbContextHelper.timeout = timeout; }
private static RouteInfo Parse(string route, string handler, string args, bool cache) { if (TextUtils.isEmpty(route) || TextUtils.isEmpty(handler)) return null; ReflectHelper reflectHelper = new ReflectHelper(); // Set up the default namespace for the handle class reflectHelper.setGlobalNamespace( GlobalSettings.NAMESPACE ); // Separate out the handle class and method RouteHandlerInfo routeHandler = reflectHelper.GetRouteHandler(handler); if (routeHandler == null) return null; string[] expectArgs = null; if (!TextUtils.isEmpty(args)) { expectArgs = args.Split(','); List<string> argBuilder = new List<string>(); // Clear up the arguments foreach (string arg in expectArgs) { if (TextUtils.isEmpty(arg)) continue; argBuilder.Add(arg.Trim()); } // Rebuild the arguments expectArgs = argBuilder.Count == 0 ? null : argBuilder.ToArray(); } return new RouteInfo(route, expectArgs, cache, routeHandler); }