private XmlNamespaceResolver EnsureCache()
        {
            if (_cache == null)
            {
                // We have to use a separate cache here because XMLNS lookups could be
                // needed by AssemblyMetadataAttribute-based relationship data.  If we
                // used AssemblyInfo.XmlNamespaceResolver directly, we'd end up in a circular
                // dependency
                _cache = new XmlNamespaceResolver();
                foreach (var a in App.DescribeAssemblies())
                {
                    var attrs = a.GetCustomAttributes(typeof(XmlnsAttribute), false);
                    foreach (XmlnsAttribute attr in attrs)
                    {
                        if (!string.IsNullOrEmpty(attr.Prefix))
                        {
                            _cache.Add(attr.Prefix, attr.Xmlns);
                        }
                    }

                    attrs = a.GetCustomAttributes(typeof(XmlnsPrefixAttribute), false);
                    foreach (XmlnsPrefixAttribute attr in attrs)
                    {
                        _cache.Add(attr.Prefix, attr.Xmlns);
                    }
                }
            }
            return(_cache);
        }
Beispiel #2
0
 public AssemblyInfoXmlNamespaceResolver(AssemblyInfo asm)
 {
     _asm      = asm;
     _resolver = new XmlNamespaceResolver(_asm.ReferencedAssemblies.Select(t => t.XmlNamespaceResolver));
     foreach (XmlnsAttribute attr in asm.Assembly.GetCustomAttributes(typeof(XmlnsAttribute), false))
     {
         AddXmlns(attr.Prefix, attr.Namespace, attr.Xmlns);
     }
     foreach (XmlnsPrefixAttribute attr in asm.Assembly.GetCustomAttributes(typeof(XmlnsPrefixAttribute), false))
     {
         _resolver.Add(attr.Prefix, attr.Xmlns);
     }
 }