Ejemplo n.º 1
0
        /// <summary>
        /// Applies the specified operation.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="context">The context.</param>
        public void Apply(Operation operation, OperationFilterContext context)
        {
            if (context.MethodInfo == null)
            {
                return;
            }

            // If method is from a constructed generic type, look for comments from the generic type method
            var targetMethod = context.MethodInfo.DeclaringType.IsConstructedGenericType
                ? GetGenericTypeMethodOrNullFor(context.MethodInfo)
                : context.MethodInfo;

            if (targetMethod == null)
            {
                return;
            }

            var memberName = XmlCommentsMemberNameHelper.GetMemberNameForMethod(targetMethod);
            var methodNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, memberName));

            if (methodNode != null)
            {
                ApplyMethodXmlToOperation(operation, methodNode);
                ApplyParamsXmlToActionParameters(operation.Parameters, methodNode, context.ServiceEntry);
                ApplyResponsesXmlToResponses(operation.Responses, methodNode.Select(ResponsesXPath));
            }

            if (context.ApiDescription != null)
            {
                // Special handling for parameters that are bound to model properties
                ApplyPropertiesXmlToPropertyParameters(operation.Parameters, context.ApiDescription);
            }
            else
            {
                ApplyPropertiesXmlToPropertyParameters(operation.Parameters, context.ServiceEntry);
            }
        }