diff --git a/src/AST/Namespace.cs b/src/AST/Namespace.cs index 74465295..6989ba45 100644 --- a/src/AST/Namespace.cs +++ b/src/AST/Namespace.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; namespace CppSharp.AST @@ -254,7 +255,8 @@ namespace CppSharp.AST if (entries.Count <= 1) { - var @class = Classes.Find(c => c.Name.Equals(name, stringComparison)); + var @class = Classes.Find(c => c.Name.Equals(name, stringComparison)) ?? + Namespaces.Select(n => n.FindClass(name, stringComparison)).FirstOrDefault(c => c != null); if (@class != null) return @class.CompleteDeclaration == null ? @class : (Class) @class.CompleteDeclaration; diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index 9e2f3199..63ade352 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -225,5 +225,11 @@ namespace CppSharp.Generator.Tests.AST Assert.IsTrue(typeDef.Type.TryGetClass(out classTemplate)); Assert.AreEqual(classTemplate, template.TemplatedClass); } + + [Test] + public void TestFindClassInNamespace() + { + Assert.IsNotNull(AstContext.FindClass("HiddenInNamespace").FirstOrDefault()); + } } } diff --git a/src/Generator.Tests/QueryHelpers.cs b/src/Generator.Tests/QueryHelpers.cs index b2ca55b1..b3c5b641 100644 --- a/src/Generator.Tests/QueryHelpers.cs +++ b/src/Generator.Tests/QueryHelpers.cs @@ -12,22 +12,22 @@ namespace CppSharp.Generator.Tests public static Class Class(this ASTContext context, string name) { - return context.FindClass(name).ToList().First(); + return context.FindClass(name).First(); } public static Function Function(this ASTContext context, string name) { - return context.FindFunction(name).ToList().First(); + return context.FindFunction(name).First(); } public static Enumeration Enum(this ASTContext context, string name) { - return context.FindEnum(name).ToList().First(); + return context.FindEnum(name).First(); } public static TypedefDecl Typedef(this ASTContext context, string name) { - return context.FindTypedef(name).ToList().First(); + return context.FindTypedef(name).First(); } public static Field Field(this Class @class, string name) diff --git a/tests/Native/AST.h b/tests/Native/AST.h index 5d7edd27..c4c1d9a5 100644 --- a/tests/Native/AST.h +++ b/tests/Native/AST.h @@ -57,3 +57,10 @@ class TestTemplateClass2 public: TestTemplateClassInt* CreateIntTemplate(); }; + +namespace HidesClass +{ + class HiddenInNamespace + { + }; +}