Exemple #1
0
        protected virtual string GetActionName(MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            IActionHttpMethodProvider actionHttpMethodProvider = method.GetCustomAttributes().OfType <IActionHttpMethodProvider>()
                                                                 .ExtendedSingle($"Finding IActionHttpMethodProvider on method {method.Name} on type {method.DeclaringType?.Name}");

            if (actionHttpMethodProvider is FunctionAttribute)
            {
                return(method.Name);
            }
            else if (actionHttpMethodProvider is ActionAttribute)
            {
                return(method.Name);
            }
            else if (actionHttpMethodProvider is GetAttribute)
            {
                return(nameof(HttpMethod.Get));
            }
            else if (actionHttpMethodProvider is CreateAttribute)
            {
                return(nameof(HttpMethod.Post));
            }
            else if (actionHttpMethodProvider is UpdateAttribute)
            {
                return(nameof(HttpMethod.Put));
            }
            else if (actionHttpMethodProvider is PartialUpdateAttribute)
            {
                return("Patch");
            }
            else if (actionHttpMethodProvider is DeleteAttribute)
            {
                return(nameof(HttpMethod.Delete));
            }

            throw new InvalidOperationException($"Invalid actionHttpMethodProvider type: {actionHttpMethodProvider.GetType().Name}");
        }