Beispiel #1
0
        void AnalyzeElement(XamlContext txt, XElement elem)
        {
            foreach (var i in elem.Attributes())
                if (i.Name.NamespaceName == "http://www.w3.org/2000/xmlns/")
                    txt.namespaces[i.Name.LocalName] = ParseXmlNs(i.Value, txt);
                else if (i.Name.LocalName == "xmlns")
                    txt.namespaces[""] = ParseXmlNs(i.Value, txt);

            XamlName name = XamlName.Parse(elem.Name, txt);
            name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns);
            if (name.TypeDef == null)
                Logger._Log("> Could not resolve '" + elem.Name.ToString() + "'!");
            else if (Assemblies.Contains(name.TypeDef.Module.Assembly))
            {
                IXmlLineInfo li = elem as IXmlLineInfo;
                string line = txt.lines[li.LineNumber - 1];
                int end = line.IndexOf(' ', li.LinePosition - 1);
                if (end == -1)
                    end = line.IndexOf('>', li.LinePosition - 1);
                string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
                var r = new XamlNameReference() { Name = name };
                txt.refers.Add(new XamlRef()
                {
                    lineNum = li.LineNumber - 1,
                    index = li.LinePosition - 1,
                    length = end - li.LinePosition + 1,
                    name = name,
                    refer = r
                });
                ((name.TypeDef as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(r);
            }

            foreach (var i in elem.Attributes())
                if (i.Name.NamespaceName != "http://www.w3.org/2000/xmlns/" &&
                    i.Name.LocalName != "xmlns")
                    AnalyzePropertyAttr(name.TypeDef, txt, i);

            foreach (var i in elem.Elements())
            {
                if (i.Name.LocalName.Contains("."))
                    AnalyzePropertyElem(name.TypeDef, txt, i);
                else
                    AnalyzeElement(txt, i);
            }
        }
        void AnalyzeElement(XamlContext txt, XElement elem)
        {
            foreach (var i in elem.Attributes())
            {
                if (i.Name.NamespaceName == "http://www.w3.org/2000/xmlns/")
                {
                    txt.namespaces[i.Name.LocalName] = ParseXmlNs(i.Value, txt);
                }
                else if (i.Name.LocalName == "xmlns")
                {
                    txt.namespaces[""] = ParseXmlNs(i.Value, txt);
                }
            }

            XamlName name = XamlName.Parse(elem.Name, txt);

            name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns);
            if (name.TypeDef == null)
            {
                Logger._Log("> Could not resolve '" + elem.Name.ToString() + "'!");
            }
            else if (Assemblies.Contains(name.TypeDef.Module.Assembly))
            {
                IXmlLineInfo li   = elem as IXmlLineInfo;
                string       line = txt.lines[li.LineNumber - 1];
                int          end  = line.IndexOf(' ', li.LinePosition - 1);
                if (end == -1)
                {
                    end = line.IndexOf('>', li.LinePosition - 1);
                }
                string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
                var    r   = new XamlNameReference()
                {
                    Name = name
                };
                txt.refers.Add(new XamlRef()
                {
                    lineNum = li.LineNumber - 1,
                    index   = li.LinePosition - 1,
                    length  = end - li.LinePosition + 1,
                    name    = name,
                    refer   = r
                });
                ((name.TypeDef as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r);
            }

            foreach (var i in elem.Attributes())
            {
                if (i.Name.NamespaceName != "http://www.w3.org/2000/xmlns/" &&
                    i.Name.LocalName != "xmlns")
                {
                    AnalyzePropertyAttr(name.TypeDef, txt, i);
                }
            }

            foreach (var i in elem.Elements())
            {
                if (i.Name.LocalName.Contains("."))
                {
                    AnalyzePropertyElem(name.TypeDef, txt, i);
                }
                else
                {
                    AnalyzeElement(txt, i);
                }
            }
        }