コード例 #1
0
        /// <summary>
        /// Resolves any <see cref="HttpControllerEndPointAttribute"/> attributes on the controller method.
        /// </summary>
        /// <param name="methodBuilder">A <see cref="IMethodBuilder"/> instance.</param>
        /// <param name="methodInfo">A method info.</param>
        /// <returns>The <see cref="IMethodBuilder"/> instance.</returns>
        public static IMethodBuilder ResolveHttpControllerEndPointAttribute(
            this IMethodBuilder methodBuilder,
            MethodInfo methodInfo)
        {
            HttpControllerEndPointAttribute attr = methodInfo?.GetCustomAttribute <HttpControllerEndPointAttribute>(false);

            if (attr != null)
            {
                if (attr.Method == HttpCallMethod.HttpGet)
                {
                    methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpGetAttribute>(attr.Route));
                }
                else if (attr.Method == HttpCallMethod.HttpPost)
                {
                    methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpPostAttribute>(attr.Route));
                }
                else if (attr.Method == HttpCallMethod.HttpPut)
                {
                    methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpPutAttribute>(attr.Route));
                }
                else if (attr.Method == HttpCallMethod.HttpPatch)
                {
                    methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpPatchAttribute>(attr.Route));
                }
                else if (attr.Method == HttpCallMethod.HttpDelete)
                {
                    methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpDeleteAttribute>(attr.Route));
                }
            }

            return(methodBuilder);
        }
コード例 #2
0
        /// <summary>
        /// Processes method attributes.
        /// </summary>
        /// <param name="methodBuilder">A method builder.</param>
        /// <param name="methodInfo">The method.</param>
        /// <returns>The method builder.</returns>
        public static IMethodBuilder ProcessAttributes(
            this IMethodBuilder methodBuilder,
            MethodInfo methodInfo)
        {
            foreach (var attr in methodInfo.GetCustomAttributes())
            {
                if (attr is ProducesAttribute)
                {
                    methodBuilder.SetCustomAttribute(
                        AttributeUtility.BuildAttribute <Type, ProducesAttribute>(
                            ((ProducesAttribute)attr).Type,
                            () => AttributeUtility.GetAttributePropertyValues <ProducesAttribute>((ProducesAttribute)attr, new[] { "Type", "ContentTypes" })));
                }
                else if (attr is ProducesResponseTypeAttribute)
                {
                    methodBuilder.SetCustomAttribute(
                        AttributeUtility.BuildAttribute <int, ProducesResponseTypeAttribute>(
                            ((ProducesResponseTypeAttribute)attr).StatusCode,
                            () => AttributeUtility.GetAttributePropertyValues <ProducesResponseTypeAttribute>((ProducesResponseTypeAttribute)attr, new[] { "type" })));
                }

/*
 *              else if (attr is SwaggerParameterAttribute)
 *              {
 *                  methodBuilder.SetCustomAttribute(
 *                      AttributeUtility.BuildAttribute<string, SwaggerParameterAttribute>(
 *                          ((SwaggerParameterAttribute)attr).ParameterName,
 *                          () => AttributeUtility.GetAttributePropertyValues<SwaggerParameterAttribute>((SwaggerParameterAttribute)attr, null)));
 *              }
 *              else if (attr is SwaggerRequestHeaderParameterAttribute)
 *              {
 *                  methodBuilder.SetCustomAttribute(
 *                      AttributeUtility.BuildAttribute<string, SwaggerRequestHeaderParameterAttribute>(
 *                          ((SwaggerRequestHeaderParameterAttribute)attr).Header,
 *                          () => AttributeUtility.GetAttributePropertyValues<SwaggerRequestHeaderParameterAttribute>((SwaggerRequestHeaderParameterAttribute)attr, null)));
 *              }
 */
                else if (attr is ObsoleteAttribute)
                {
                    methodBuilder.SetCustomAttribute(
                        AttributeUtility.BuildAttribute <ObsoleteAttribute>(null));
                }
            }

            return(methodBuilder);
        }
コード例 #3
0
        /// <summary>
        /// Resolves any Mvc attributes on the method.
        /// </summary>
        /// <param name="methodBuilder">The method being built.</param>
        /// <param name="methodInfo">The method being called.</param>
        /// <returns>True if any resolved; otherwise false.</returns>
        public static bool ResolveMvcAttributes(
            this IMethodBuilder methodBuilder,
            MethodInfo methodInfo)
        {
            HttpGetAttribute getAttr = methodInfo.GetCustomAttribute <HttpGetAttribute>(true);

            if (getAttr != null)
            {
                methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpGetAttribute>(getAttr.Template));
                return(true);
            }

            HttpPostAttribute postAttr = methodInfo.GetCustomAttribute <HttpPostAttribute>(true);

            if (postAttr != null)
            {
                methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpPostAttribute>(postAttr.Template));
                return(true);
            }

            HttpPutAttribute putAttr = methodInfo.GetCustomAttribute <HttpPutAttribute>(true);

            if (putAttr != null)
            {
                methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpPutAttribute>(putAttr.Template));
                return(true);
            }

            HttpPatchAttribute patchAttr = methodInfo.GetCustomAttribute <HttpPatchAttribute>(true);

            if (patchAttr != null)
            {
                methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpPatchAttribute>(patchAttr.Template));
                return(true);
            }

            HttpDeleteAttribute deleteAttr = methodInfo.GetCustomAttribute <HttpDeleteAttribute>(true);

            if (deleteAttr != null)
            {
                methodBuilder.SetCustomAttribute(AttributeUtility.BuildAttribute <string, HttpDeleteAttribute>(deleteAttr.Template));
                return(true);
            }

            return(false);
        }