From 1e1db1f8ffaefd1661a8835c411943aedb13d9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Taylor=20Ienczak=20Zanette?= Date: Fri, 18 Dec 2020 17:31:16 -0300 Subject: [PATCH 1/3] Support clr-namespace for namespace declaration as well --- OmniXaml/TypeLocation/TypeDirectory.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/OmniXaml/TypeLocation/TypeDirectory.cs b/OmniXaml/TypeLocation/TypeDirectory.cs index 6ddc423..b962859 100644 --- a/OmniXaml/TypeLocation/TypeDirectory.cs +++ b/OmniXaml/TypeLocation/TypeDirectory.cs @@ -6,7 +6,6 @@ public class TypeDirectory : ITypeDirectory { - private const string ClrNamespace = "using:"; private readonly ISet xamlNamespaces; public TypeDirectory(IEnumerable xamlNamespaces) @@ -37,13 +36,22 @@ private Namespace GetNamespace(string name) { return TypeLocation.ClrNamespace.ExtractNamespace(name); } - + return xamlNamespaces.FirstOrDefault(xamlNamespace => xamlNamespace.Name == name); } private static bool IsClrNamespace(string ns) { - return ns.StartsWith(ClrNamespace); + var namespaceDeclarations = new string[] { "using:", "clr-namespace:" }; + foreach (var decl in namespaceDeclarations) + { + if (ns.StartsWith(decl)) + { + return true; + } + } + + return false; } } -} \ No newline at end of file +} From 89a46800d9d6f2bc7263a7111a20923854a6bdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Taylor=20Ienczak=20Zanette?= Date: Fri, 18 Dec 2020 17:38:21 -0300 Subject: [PATCH 2/3] Simplify namespace declaration check --- OmniXaml/TypeLocation/TypeDirectory.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/OmniXaml/TypeLocation/TypeDirectory.cs b/OmniXaml/TypeLocation/TypeDirectory.cs index b962859..b8f8c3b 100644 --- a/OmniXaml/TypeLocation/TypeDirectory.cs +++ b/OmniXaml/TypeLocation/TypeDirectory.cs @@ -36,22 +36,15 @@ private Namespace GetNamespace(string name) { return TypeLocation.ClrNamespace.ExtractNamespace(name); } - + return xamlNamespaces.FirstOrDefault(xamlNamespace => xamlNamespace.Name == name); } private static bool IsClrNamespace(string ns) { - var namespaceDeclarations = new string[] { "using:", "clr-namespace:" }; - foreach (var decl in namespaceDeclarations) - { - if (ns.StartsWith(decl)) - { - return true; - } - } + var namespaceDeclarations = new List{ "using:", "clr-namespace:" }; - return false; + return namespaceDeclarations.Exists(decl => ns.StartsWith(decl)); } } } From 020bc3a830c96861f3dc61fbbc5f69fb26dbb31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Taylor=20Ienczak=20Zanette?= Date: Fri, 18 Dec 2020 18:02:57 -0300 Subject: [PATCH 3/3] Prevent local object reinitialization for every `IsClrNamespace` call. --- OmniXaml/TypeLocation/TypeDirectory.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OmniXaml/TypeLocation/TypeDirectory.cs b/OmniXaml/TypeLocation/TypeDirectory.cs index b8f8c3b..2f3b252 100644 --- a/OmniXaml/TypeLocation/TypeDirectory.cs +++ b/OmniXaml/TypeLocation/TypeDirectory.cs @@ -6,6 +6,7 @@ public class TypeDirectory : ITypeDirectory { + private static readonly List namespaceDeclarations = new List { "using:", "clr-namespace:" }; private readonly ISet xamlNamespaces; public TypeDirectory(IEnumerable xamlNamespaces) @@ -42,8 +43,6 @@ private Namespace GetNamespace(string name) private static bool IsClrNamespace(string ns) { - var namespaceDeclarations = new List{ "using:", "clr-namespace:" }; - return namespaceDeclarations.Exists(decl => ns.StartsWith(decl)); } }