public void Apply(Schema model, ModelFilterContext context)
        {
            XPathNavigator navigator;

            lock (this._xmlDoc)
                navigator = this._xmlDoc.CreateNavigator();
            string         commentIdForType = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            XPathNavigator xpathNavigator   = navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)commentIdForType));

            if (xpathNavigator != null)
            {
                XPathNavigator node = xpathNavigator.SelectSingleNode("summary");
                if (node != null)
                {
                    model.description = node.ExtractContent();
                }
            }
            if (model.properties == null)
            {
                return;
            }
            foreach (KeyValuePair <string, Schema> property1 in (IEnumerable <KeyValuePair <string, Schema> >)model.properties)
            {
                JsonProperty property2 = ((KeyedCollection <string, JsonProperty>)context.JsonObjectContract.get_Properties())[property1.Key];
                if (property2 != null)
                {
                    ApplyXmlTypeComments.ApplyPropertyComments(navigator, property1.Value, property2.PropertyInfo());
                }
            }
        }
示例#2
0
        public void Apply(Operation operation, string commentIdForMethod /*,SchemaRegistry schemaRegistry, ApiDescription apiDescription*/)
        {
            //ReflectedHttpActionDescriptor reflectedHttpActionDescriptor = apiDescription.ActionDescriptor as ReflectedHttpActionDescriptor;
            //if (reflectedHttpActionDescriptor == null)
            //{
            //    return;
            //}
            //string commentIdForMethod = XmlCommentsIdHelper.GetCommentIdForMethod(reflectedHttpActionDescriptor.MethodInfo);
            XPathNavigator xPathNavigator = this._navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", commentIdForMethod));

            if (xPathNavigator == null)
            {
                return;
            }
            XPathNavigator xPathNavigator2 = xPathNavigator.SelectSingleNode("summary");

            if (xPathNavigator2 != null)
            {
                operation.summary = xPathNavigator2.ExtractContent();
            }
            XPathNavigator xPathNavigator3 = xPathNavigator.SelectSingleNode("remarks");

            if (xPathNavigator3 != null)
            {
                operation.description = xPathNavigator3.ExtractContent();
            }
            ApplyXmlActionComments.ApplyParamComments(operation, xPathNavigator);
            ApplyXmlActionComments.ApplyResponseComments(operation, xPathNavigator);
        }
示例#3
0
 private static void ApplyParamComments(
     Operation operation,
     XPathNavigator methodNode,
     MethodInfo method)
 {
     if (operation.parameters == null)
     {
         return;
     }
     foreach (Parameter parameter1 in (IEnumerable <Parameter>)operation.parameters)
     {
         Parameter     parameter     = parameter1;
         ParameterInfo parameterInfo = ((IEnumerable <ParameterInfo>)method.GetParameters()).FirstOrDefault <ParameterInfo>((Func <ParameterInfo, bool>)(paramInfo =>
         {
             if (!ApplyXmlActionComments.HasBoundName(paramInfo, parameter.name))
             {
                 return(paramInfo.Name == parameter.name);
             }
             return(true);
         }));
         if (parameterInfo != null)
         {
             XPathNavigator node = methodNode.SelectSingleNode(string.Format("param[@name='{0}']", (object)parameterInfo.Name));
             if (node != null)
             {
                 parameter.description = node.ExtractContent();
             }
         }
     }
 }
        public void XPathNavigator_null()
        {
            XPathNavigator navigator = null;
            string         content   = navigator.ExtractContent();

            Assert.AreEqual(null, content);
        }
        public void XPathNavigator_reads_ConstPattern()
        {
            string        xml = "<doc><c>test<display>one</display></c><c>test<display>two</display></c></doc>";
            XPathDocument xmlDoc;

            using (StringReader stream = new StringReader(xml))
            {
                xmlDoc = new XPathDocument(stream);
            }
            XPathNavigator navigator = xmlDoc.CreateNavigator();
            string         content   = navigator.ExtractContent();

            Assert.AreEqual(xml.Replace("<c>", "").Replace("</c>", ""), content.Strip());
        }
        public void XPathNavigator_reads_empty_doc()
        {
            string        xml = "<doc></doc>";
            XPathDocument xmlDoc;

            using (StringReader stream = new StringReader(xml))
            {
                xmlDoc = new XPathDocument(stream);
            }
            XPathNavigator navigator = xmlDoc.CreateNavigator();
            string         content   = navigator.ExtractContent();

            Assert.AreEqual(xml, content);
        }
示例#7
0
        private static void ApplyParamComments(Operation operation, XPathNavigator methodNode)
        {
            if (operation.parameters == null)
            {
                return;
            }
            XPathNodeIterator xPathNodeIterator = methodNode.Select("param");

            while (xPathNodeIterator.MoveNext())
            {
                XPathNavigator paramNode = xPathNodeIterator.Current;
                Parameter      parameter = operation.parameters.SingleOrDefault((Parameter param) => param.name == paramNode.GetAttribute("name", ""));
                if (parameter != null)
                {
                    parameter.description = paramNode.ExtractContent();
                }
            }
        }
        private void ApplyPropertyComments(Schema propertySchema, PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                return;
            }
            string         commentIdForProperty = XmlCommentsIdHelper.GetCommentIdForProperty(propertyInfo);
            XPathNavigator xPathNavigator       = this._navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", commentIdForProperty));

            if (xPathNavigator == null)
            {
                return;
            }
            XPathNavigator xPathNavigator2 = xPathNavigator.SelectSingleNode("summary");

            if (xPathNavigator2 != null)
            {
                propertySchema.description = xPathNavigator2.ExtractContent();
            }
        }
        public void Apply(Schema model, ModelFilterContext context)
        {
            string         commentIdForType = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            XPathNavigator xPathNavigator   = this._navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", commentIdForType));

            if (xPathNavigator != null)
            {
                XPathNavigator xPathNavigator2 = xPathNavigator.SelectSingleNode("summary");
                if (xPathNavigator2 != null)
                {
                    model.description = xPathNavigator2.ExtractContent();
                }
            }
            foreach (KeyValuePair <string, Schema> current in model.properties)
            {
                JsonProperty jsonProperty = context.JsonObjectContract.Properties[current.Key];
                if (jsonProperty != null)
                {
                    this.ApplyPropertyComments(current.Value, jsonProperty.PropertyInfo());
                }
            }
        }
示例#10
0
        public void Apply(
            Operation operation,
            SchemaRegistry schemaRegistry,
            ApiDescription apiDescription)
        {
            ReflectedHttpActionDescriptor actionDescriptor = apiDescription.get_ActionDescriptor() as ReflectedHttpActionDescriptor;

            if (actionDescriptor == null)
            {
                return;
            }
            XPathNavigator navigator;

            lock (this._xmlDoc)
                navigator = this._xmlDoc.CreateNavigator();
            string         commentIdForMethod = XmlCommentsIdHelper.GetCommentIdForMethod(actionDescriptor.get_MethodInfo());
            XPathNavigator methodNode         = navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)commentIdForMethod));

            if (methodNode == null)
            {
                return;
            }
            XPathNavigator node1 = methodNode.SelectSingleNode("summary");

            if (node1 != null)
            {
                operation.summary = node1.ExtractContent();
            }
            XPathNavigator node2 = methodNode.SelectSingleNode("remarks");

            if (node2 != null)
            {
                operation.description = node2.ExtractContent();
            }
            ApplyXmlActionComments.ApplyParamComments(operation, methodNode, actionDescriptor.get_MethodInfo());
            ApplyXmlActionComments.ApplyResponseComments(operation, methodNode);
        }
        private static void ApplyPropertyComments(
            XPathNavigator navigator,
            Schema propertySchema,
            PropertyInfo propertyInfo)
        {
            if (propertyInfo == (PropertyInfo)null)
            {
                return;
            }
            string         commentIdForProperty = XmlCommentsIdHelper.GetCommentIdForProperty(propertyInfo);
            XPathNavigator xpathNavigator       = navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)commentIdForProperty));

            if (xpathNavigator == null)
            {
                return;
            }
            XPathNavigator node = xpathNavigator.SelectSingleNode("summary");

            if (node == null)
            {
                return;
            }
            propertySchema.description = node.ExtractContent();
        }