コード例 #1
0
ファイル: XamlType.cs プロジェクト: yariker/Portable.Xaml
        IEnumerable <string> DoGetXamlNamespaces()
        {
            // not quite sure if this is correct, but matches documentation to get all namespaces that type exists in
            if (!string.IsNullOrEmpty(explicit_ns))
            {
                yield return(explicit_ns);
            }

            if (type != null)
            {
                var assemblyName = type.GetTypeInfo().Assembly.GetName().Name;
                if (mscorlib_assemblies.Contains(assemblyName))
                {
                    assemblyName = "mscorlib";
                }
                // type always exists in clr namespace
                yield return($"clr-namespace:{type.Namespace};assembly={assemblyName}");

                // check if it's a built-in type
                if (XamlLanguage.AllTypes.Any(r => r.UnderlyingType == type))
                {
                    yield return(XamlLanguage.Xaml2006Namespace);
                }

                // check all other registered namespaces (may duplicate for built-in types, such as xaml markup extensions)
                foreach (var ns in SchemaContext.GetAllXamlNamespaces())
                {
                    if (SchemaContext.GetAllXamlTypes(ns).Any(r => r.UnderlyingType == type))
                    {
                        yield return(ns);
                    }
                }
            }
        }
コード例 #2
0
        public virtual IList <string> GetXamlNamespaces()
        {
            // not quite sure if this is correct, but matches documentation to get all namespaces that type exists in
            var list = new List <string>();

            if (!string.IsNullOrEmpty(explicit_ns))
            {
                list.Add(explicit_ns);
            }

            if (type != null)
            {
                // type always exists in clr namespace
                list.Add(string.Format("clr-namespace:{0};assembly={1}", type.Namespace, type.GetTypeInfo().Assembly.GetName().Name));

                // check if it's a built-in type
                if (XamlLanguage.AllTypes.Any(r => r.UnderlyingType == type))
                {
                    list.Add(XamlLanguage.Xaml2006Namespace);
                }

                // check all other registered namespaces (may duplicate for built-in types, such as xaml markup extensions)
                foreach (var ns in SchemaContext.GetAllXamlNamespaces())
                {
                    if (SchemaContext.GetAllXamlTypes(ns).Any(r => r.UnderlyingType == type))
                    {
                        list.Add(ns);
                    }
                }
            }
            if (list.Count == 0)
            {
                return new [] { string.Empty }
            }
            ;

            return(new ReadOnlyCollection <string> (list));
        }