public JsControllerMethodParameter(string paramtername, string description, JsControllerMethodInfo.DataType dataType, bool isNecessary = true) { Parametername = paramtername; Description = description; DataType = dataType; IsNecessary = isNecessary; }
public JsControllerMethodReturnValue(string description, JsControllerMethodInfo.DataType datatype) { Description = description; DataType = datatype; }
public static List <JsControllerMethodInfo> GetGenericJsControllerInfo(Type jsController) { Logger.Log("Creating generic JsController info for " + jsController.Name, Logger.LogLevel.debug); bool browserContext = jsController.GetInterfaces().Contains(typeof(IBrowserContextCallable)); bool jintContext = jsController.GetInterfaces().Contains(typeof(IJintContextCallable)); if (!browserContext && !jintContext) { throw new ArgumentException("Given type must inherit either IBrowserContextCallable and/or IJintContextCallable", "jsController"); } var methodInfos = new List <JsControllerMethodInfo>(); var methods = jsController.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (var method in methods) { // ingore default methods if (_defaultMethodNames == null) { _defaultMethodNames = new List <string>(); foreach (var m in typeof(object).GetMethods()) { _defaultMethodNames.Add(m.Name); } } if (_defaultMethodNames.Contains(method.Name)) { continue; } var parameters = method.GetParameters(); var newParameters = new List <JsControllerMethodParameter>(); foreach (var parameter in parameters) { JsControllerMethodInfo.DataType paramType = JsControllerMethodInfo.DataType.text; bool isBoolean = parameter.ParameterType == typeof(bool); if (isBoolean) { paramType = JsControllerMethodInfo.DataType.boolean; } bool isNumber = parameter.ParameterType == typeof(Int32) || parameter.ParameterType == typeof(Int64) || parameter.ParameterType == typeof(Int16) || parameter.ParameterType == typeof(float) || parameter.ParameterType == typeof(double); if (isNumber) { paramType = JsControllerMethodInfo.DataType.number; } if (parameter.ParameterType == typeof(Array) || (parameter.ParameterType.IsGenericType && (parameter.ParameterType.GetGenericTypeDefinition() == typeof(List <>)))) { paramType = JsControllerMethodInfo.DataType.array; } newParameters.Add(new JsControllerMethodParameter( parameter.Name, null, paramType, !parameter.IsOptional )); } JsControllerMethodReturnValue returnValue = null; if (method.ReturnType != typeof(void)) { bool isDict = method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Dictionary <,>); if (isDict) { returnValue = new JsControllerMethodReturnValue("", JsControllerMethodInfo.DataType.dictionary); } bool isBoolean = method.ReturnType == typeof(bool); if (isBoolean) { returnValue = new JsControllerMethodReturnValue("", JsControllerMethodInfo.DataType.boolean); } bool isNumber = method.ReturnType == typeof(Int32) || method.ReturnType == typeof(Int64) || method.ReturnType == typeof(Int16) || method.ReturnType == typeof(float) || method.ReturnType == typeof(double); if (isNumber) { returnValue = new JsControllerMethodReturnValue("", JsControllerMethodInfo.DataType.number); } if (method.ReturnType == typeof(Array) || (method.ReturnType.IsGenericType && (method.ReturnType.GetGenericTypeDefinition() == typeof(List <>)))) { returnValue = new JsControllerMethodReturnValue("", JsControllerMethodInfo.DataType.array); } // none of the above? => generic text if (returnValue == null) { returnValue = new JsControllerMethodReturnValue("", JsControllerMethodInfo.DataType.text); } } methodInfos.Add(new JsControllerMethodInfo(method.Name, null, newParameters, returnValue)); } return(methodInfos); }