示例#1
0
        /// <summary>
        /// Gets a collection of defined prefix-namespace mappings that are currently in scope.
        /// </summary>
        public IDictionary <string, string> GetNamespacesInScope(XmlNamespaceScope scope)
        {
            var result = new Dictionary <string, string>();

            if (scope == XmlNamespaceScope.All)
            {
                result["xml"] = XmlNamespace;
                //result["xmlns"] = XmlnsNamespace; xmlns should not be included in GetNamespacesInScope() results
            }
            for (AXmlElement current = this; current != null; current = current.Parent as AXmlElement)
            {
                foreach (var attr in current.Attributes)
                {
                    if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal))
                    {
                        string prefix = attr.LocalName;
                        if (!result.ContainsKey(prefix))
                        {
                            result.Add(prefix, attr.Value);
                        }
                    }
                    else if (attr.Name == "xmlns" && !result.ContainsKey(string.Empty))
                    {
                        result.Add(string.Empty, attr.Value);
                    }
                }
                if (scope == XmlNamespaceScope.Local)
                {
                    break;
                }
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Recursively resolve given prefix in this context.
        /// </summary>
        /// <returns><c>null</c> if prefix is not found</returns>
        public string LookupNamespace(string prefix)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }

            // Implicit namespaces
            if (prefix == "xml")
            {
                return(XmlNamespace);
            }
            if (prefix == "xmlns")
            {
                return(XmlnsNamespace);
            }

            string lookFor = (prefix.Length > 0 ? "xmlns:" + prefix : "xmlns");

            for (AXmlElement current = this; current != null; current = current.Parent as AXmlElement)
            {
                foreach (var attr in current.Attributes)
                {
                    if (attr.Name == lookFor)
                    {
                        return(attr.Value);
                    }
                }
            }
            return(null);            // Can not find prefix
        }
示例#3
0
        /// <summary>
        /// Gets the prefix that is mapped to the specified namespace URI.
        /// </summary>
        /// <returns>The prefix that is mapped to the namespace URI; null if the namespace URI is not mapped to a prefix.</returns>
        public string LookupPrefix(string namespaceName)
        {
            if (namespaceName == null)
            {
                throw new ArgumentNullException("namespaceName");
            }

            if (namespaceName == XmlNamespace)
            {
                return("xml");
            }
            if (namespaceName == XmlnsNamespace)
            {
                return("xmlns");
            }
            for (AXmlElement current = this; current != null; current = current.Parent as AXmlElement)
            {
                foreach (var attr in current.Attributes)
                {
                    if (attr.Value == namespaceName)
                    {
                        if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal))
                        {
                            return(attr.LocalName);
                        }
                        else if (attr.Name == "xmlns")
                        {
                            return(string.Empty);
                        }
                    }
                }
            }
            return(null);            // Can not find prefix
        }
示例#4
0
 /// <summary> Visit AXmlElement </summary>
 public virtual void VisitElement(AXmlElement element)
 {
     foreach (AXmlObject child in element.Children)
     {
         child.AcceptVisitor(this);
     }
 }
 /// <summary>
 /// Creates a new documentation element.
 /// </summary>
 public XmlDocumentationElement(AXmlElement element, IEntity declaringEntity, Func<string, IEntity> crefResolver)
 {
     if (element == null)
         throw new ArgumentNullException("element");
     this.element = element;
     this.xmlObject = element;
     this.declaringEntity = declaringEntity;
     this.crefResolver = crefResolver;
 }
示例#6
0
 /// <summary>
 /// Creates a new documentation element.
 /// </summary>
 public XmlDocumentationElement(AXmlElement element, IEntity declaringEntity, Func <string, IEntity> crefResolver)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     this.element         = element;
     this.xmlObject       = element;
     this.declaringEntity = declaringEntity;
     this.crefResolver    = crefResolver;
 }
		XamlOutlineNode BuildNode(AXmlElement item)
		{
			XamlOutlineNode node = new XamlOutlineNode {
				Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"),
				ElementName = item.Name,
				Marker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)),
				EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)),
				Editor = editor
			};
			
			foreach (var child in item.Children.OfType<AXmlElement>())
				node.Children.Add(BuildNode(child));
			
			return node;
		}
		internal ResolveResult ResolveElement(AXmlElement element, CancellationToken cancellationToken = default(CancellationToken))
		{
			string namespaceName = element.Namespace;
			string name = element.LocalName;
			if (name.Contains(".")) {
				string propertyName = name.Substring(name.IndexOf('.') + 1);
				name = name.Substring(0, name.IndexOf('.'));
				ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(namespaceName, name);
				IType type = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
				IMember member = FindMember(type, propertyName);
				IMember underlying = null;
				if (member == null)
					member = FindAttachedMember(type, propertyName, out underlying);
				if (member == null)
					return new UnknownMemberResolveResult(type, propertyName, EmptyList<IType>.Instance);
				if (underlying != null)
					return new AttachedMemberResolveResult(new TypeResolveResult(type), underlying, member);
				return new MemberResolveResult(new TypeResolveResult(type), member);
			} else {
				ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(namespaceName, name);
				IType type = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
				return new TypeResolveResult(type);
			}
		}
示例#9
0
        static List <XmlDocumentationElement> CreateElements(IEnumerable <AXmlObject> childObjects, IEntity declaringEntity, Func <string, IEntity> crefResolver, int nestingLevel)
        {
            List <XmlDocumentationElement> list = new List <XmlDocumentationElement>();

            foreach (var child in childObjects)
            {
                var childText    = child as AXmlText;
                var childTag     = child as AXmlTag;
                var childElement = child as AXmlElement;
                if (childText != null)
                {
                    list.Add(new XmlDocumentationElement(childText.Value, declaringEntity));
                }
                else if (childTag != null && childTag.IsCData)
                {
                    foreach (var text in childTag.Children.OfType <AXmlText>())
                    {
                        list.Add(new XmlDocumentationElement(text.Value, declaringEntity));
                    }
                }
                else if (childElement != null)
                {
                    if (nestingLevel < 5 && childElement.Name == "inheritdoc")
                    {
                        string  cref          = childElement.GetAttributeValue("cref");
                        IEntity inheritedFrom = null;
                        DocumentationComment inheritedDocumentation = null;
                        if (cref != null)
                        {
                            inheritedFrom = crefResolver(cref);
                            if (inheritedFrom != null)
                            {
                                inheritedDocumentation = inheritedFrom.Documentation;
                            }
                        }
                        else
                        {
                            foreach (IMember baseMember in InheritanceHelper.GetBaseMembers((IMember)declaringEntity, includeImplementedInterfaces: true))
                            {
                                inheritedDocumentation = baseMember.Documentation;
                                if (inheritedDocumentation != null)
                                {
                                    inheritedFrom = baseMember;
                                    break;
                                }
                            }
                        }

                        if (inheritedDocumentation != null)
                        {
                            var doc = new AXmlParser().Parse(inheritedDocumentation.Xml);

                            // XPath filter not yet implemented
                            if (childElement.Parent is AXmlDocument && childElement.GetAttributeValue("select") == null)
                            {
                                // Inheriting documentation at the root level
                                List <string> doNotInherit = new List <string>();
                                doNotInherit.Add("overloads");
                                doNotInherit.AddRange(childObjects.OfType <AXmlElement>().Select(e => e.Name).Intersect(
                                                          doNotInheritIfAlreadyPresent));

                                var inheritedChildren = doc.Children.Where(
                                    inheritedObject => {
                                    AXmlElement inheritedElement = inheritedObject as AXmlElement;
                                    return(!(inheritedElement != null && doNotInherit.Contains(inheritedElement.Name)));
                                });

                                list.AddRange(CreateElements(inheritedChildren, inheritedFrom, inheritedDocumentation.ResolveCref, nestingLevel + 1));
                            }
                        }
                    }
                    else
                    {
                        list.Add(new XmlDocumentationElement(childElement, declaringEntity, crefResolver)
                        {
                            nestingLevel = nestingLevel
                        });
                    }
                }
            }
            if (list.Count > 0 && list[0].IsTextNode)
            {
                if (string.IsNullOrWhiteSpace(list[0].textContent))
                {
                    list.RemoveAt(0);
                }
                else
                {
                    list[0].textContent = list[0].textContent.TrimStart();
                }
            }
            if (list.Count > 0 && list[list.Count - 1].IsTextNode)
            {
                if (string.IsNullOrWhiteSpace(list[list.Count - 1].textContent))
                {
                    list.RemoveAt(list.Count - 1);
                }
                else
                {
                    list[list.Count - 1].textContent = list[list.Count - 1].textContent.TrimEnd();
                }
            }
            return(list);
        }
示例#10
0
		/// <summary> Visit AXmlElement </summary>
		public virtual void VisitElement(AXmlElement element)
		{
			foreach (AXmlObject child in element.Children)
				child.AcceptVisitor(this);
		}
示例#11
0
			public override void VisitElement(AXmlElement element)
			{
				string name = element.GetAttributeValue(XamlConst.XamlNamespace, "Name") ??
					element.GetAttributeValue("Name");
				string modifier = element.GetAttributeValue(XamlConst.XamlNamespace, "FieldModifier");
				
				if (name != null && TypeDefinition != null) {
					var field = new DefaultUnresolvedField(TypeDefinition, name);
					field.Accessibility = Accessibility.Internal;
					field.ReturnType = CreateTypeReference(element.Namespace, element.LocalName);
					field.Region = new DomRegion(file.FileName, textDocument.GetLocation(element.StartOffset), textDocument.GetLocation(element.EndOffset));
					if (modifier != null)
						field.Accessibility = ParseAccessibility(modifier);
					TypeDefinition.Members.Add(field);
				}
				
				base.VisitElement(element);
			}
示例#12
0
		XamlOutlineNode BuildNode(AXmlElement item)
		{
			XamlOutlineNode node = new XamlOutlineNode {
				Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"),
				ElementName = item.Name,
				StartMarker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)),
				EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)),
				Editor = editor,
				XmlNodeItem = item
			};
			
			node.StartLocation = new TextLocation(node.StartMarker.Line, node.StartMarker.Column);
			node.EndLocation = new TextLocation(node.EndMarker.Line, node.EndMarker.Column);
			node.IsExpanded = true;
			
			foreach (var child in item.Children.OfType<AXmlElement>())
				node.Children.Add(BuildNode(child));
			
			return node;
		}