Ejemplo n.º 1
0
        private static DynamicApiRepositoryAction CreateAction(IRepositoryManager repositoryManager, string repositoryName, string actionName, MethodInfo method, MethodInfo interfaceMethod)
        {
            var action = new DynamicApiRepositoryAction
            {
                RepositoryManager = repositoryManager,
                RepositoryName    = repositoryName,
                Parameters        = DynamicApiActionParameter.GetParameters(interfaceMethod),
                Path = new DynamicApiActionPath(repositoryName, actionName),
            };

            action.SetMethod(method);
            return(action);
        }
Ejemplo n.º 2
0
        private object ParseGetValue(DynamicApiActionParameter actionParameter, StringValues queryParam)
        {
            try
            {
                if (actionParameter.Type == typeof(DateTime))
                {
                    return(DateTime.ParseExact(queryParam.ToString(), _dateTimeConverter.DateTimeFormat, null));
                }

                var converter = TypeDescriptor.GetConverter(actionParameter.Type);
                return(converter.ConvertFrom(queryParam.ToString()));
            }
            catch (NotSupportedException)
            {
                return(JsonConvert.DeserializeObject(queryParam.ToString(), actionParameter.Type, _jsonSerializer));
            }
        }
        /// <summary>
        /// Register a controller and it's actions.
        /// </summary>
        public void RegisterController(Type type)
        {
            var actions = type.GetMethods().Where(e => Attribute.IsDefined((MemberInfo)e, typeof(ApiActionAttribute)));

            foreach (var action in actions)
            {
                var attribute = action.GetCustomAttribute <ApiActionAttribute>();
                var path      = attribute.Path.Split('/');

                var controllerAction = new DynamicApiControllersAction(_container)
                {
                    Path           = new DynamicApiActionPath(path[0], path[1]),
                    ControllerType = type,
                    Parameters     = DynamicApiActionParameter.GetParameters(action),
                };
                controllerAction.SetMethod(action);
                _actions.Add(controllerAction);
            }
        }
Ejemplo n.º 4
0
 private object ParsePostValue(DynamicApiActionParameter actionParameter, string content)
 {
     return(JsonConvert.DeserializeObject(content, actionParameter.Type, _jsonSerializer));
 }