예제 #1
0
        /// <summary>
        /// Recursively resolve given prefix in this context.  Prefix must have some value.
        /// </summary>
        /// <returns> Empty string if prefix is not found </returns>
        public string ResolvePrefix(string prefix)
        {
            if (string.IsNullOrEmpty(prefix))
            {
                throw new ArgumentException("No prefix given", "prefix");
            }

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

            AXmlElement current = this;

            while (current != null)
            {
                string namesapce = current.GetAttributeValue(XmlnsNamespace, prefix);
                if (namesapce != null)
                {
                    return(namesapce);
                }
                current = current.Parent as AXmlElement;
            }
            return(NoNamespace);            // Can not find prefix
        }
예제 #2
0
        /// <summary> Find the defualt namespace for this context </summary>
        public string FindDefaultNamespace()
        {
            AXmlElement current = this;

            while (current != null)
            {
                string namesapce = current.GetAttributeValue(NoNamespace, "xmlns");
                if (namesapce != null)
                {
                    return(namesapce);
                }
                current = current.Parent as AXmlElement;
            }
            return(string.Empty);            // No namesapce
        }
		IClass AddClass(string className, AXmlElement element) {
			if (projectContent.Language == LanguageProperties.VBNet && projectContent.Project is IProject)
				className = ((IProject)projectContent.Project).RootNamespace + "." + className;
			
			DefaultClass c = new DefaultClass(CompilationUnit, className);
			string modifierValue = (element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "ClassModifier") ?? string.Empty).Trim();
			
			c.Modifiers = ModifierEnum.Partial;
			
			string internalString = currentAmbience.ConvertAccessibility(ModifierEnum.Internal).Trim();
			
			if (projectContent.Language.NameComparer.Compare(modifierValue, internalString) == 0)
				c.Modifiers |= ModifierEnum.Internal;
			else
				c.Modifiers |= ModifierEnum.Public;
			
			c.Region = CreateRegion(element.StartOffset, element.EndOffset);
			var baseType = TypeFromXmlNode(CompilationUnit, element);
			if (baseType != null)
				c.BaseTypes.Add(baseType);
			CompilationUnit.Classes.Add(c);

			DefaultMethod initializeComponent = new DefaultMethod(
				"InitializeComponent",
				projectContent.SystemTypes.Void,
				ModifierEnum.Public | ModifierEnum.Synthetic, c.Region, DomRegion.Empty,
				c);
			c.Methods.Add(initializeComponent);
			
			return c;
		}
		public override void VisitElement(AXmlElement element)
		{
			AXmlTag tag = element.Children.FirstOrDefault() as AXmlTag;
			
			if (tag != null && tag.IsStartOrEmptyTag) {
				NodeWrapper node = new NodeWrapper() {
					ElementName = element.LocalName,
					StartOffset = element.StartOffset,
					EndOffset = element.EndOffset,
					Name = element.GetAttributeValue("Name") ?? element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "Name"),
					Children = new List<NodeWrapper>()
				};
				
				if (CompilationUnit.TreeRootNode == null) {
					CompilationUnit.TreeRootNode = node;
					nodeStack.Push(CompilationUnit.TreeRootNode);
				} else {
					if (nodeStack.Count > 0)
						nodeStack.Peek().Children.Add(node);
					if (!tag.IsEmptyTag)
						nodeStack.Push(node);
				}
			}
			
			base.VisitElement(element);
			
			if (tag != null && tag.IsStartTag)
				nodeStack.PopOrDefault();
		}