Example #1
0
        IEnumerable <string> ResolveCLRNamespaces(IModule assembly, string ns)
        {
            foreach (var attr in assembly.GetAssemblyAttributes().Where(a => a.AttributeType.FullName == "System.Windows.Markup.XmlnsDefinitionAttribute"))
            {
                Debug.Assert(attr.FixedArguments.Length == 2);

                var xmlNs = attr.FixedArguments[0].Value;
                var clrNs = attr.FixedArguments[1].Value;
                Debug.Assert(xmlNs is string && clrNs is string);

                if ((string)xmlNs == ns)
                {
                    yield return((string)clrNs);
                }
            }
        }
Example #2
0
        public string TryGetXmlNamespace(IModule assembly, string typeNamespace)
        {
            if (assembly == null)
            {
                return(null);
            }

            HashSet <string> possibleXmlNs = new HashSet <string>();

            foreach (var attr in assembly.GetAssemblyAttributes().Where(a => a.AttributeType.FullName == "System.Windows.Markup.XmlnsDefinitionAttribute"))
            {
                Debug.Assert(attr.FixedArguments.Length == 2);
                if (attr.FixedArguments.Length != 2)
                {
                    continue;
                }
                var xmlNs  = attr.FixedArguments[0].Value as string;
                var typeNs = attr.FixedArguments[1].Value as string;
                Debug.Assert((object)xmlNs != null && (object)typeNs != null);
                if ((object)xmlNs == null || (object)typeNs == null)
                {
                    continue;
                }

                if (typeNamespace == typeNs)
                {
                    possibleXmlNs.Add(xmlNs);
                }
            }

            if (possibleXmlNs.Contains("http://schemas.microsoft.com/winfx/2006/xaml/presentation"))
            {
                return("http://schemas.microsoft.com/winfx/2006/xaml/presentation");
            }

            return(possibleXmlNs.FirstOrDefault());
        }
 public static void CollectAttributeNamespaces(IModule module, HashSet <string> namespaces)
 {
     HandleAttributes(module.GetAssemblyAttributes(), namespaces);
     HandleAttributes(module.GetModuleAttributes(), namespaces);
 }