diff --git a/src/DtoGenerator/DtoGenerator.Logic/Infrastructure/EntityParser.cs b/src/DtoGenerator/DtoGenerator.Logic/Infrastructure/EntityParser.cs
index 3d95e51..209a694 100644
--- a/src/DtoGenerator/DtoGenerator.Logic/Infrastructure/EntityParser.cs
+++ b/src/DtoGenerator/DtoGenerator.Logic/Infrastructure/EntityParser.cs
@@ -162,7 +162,11 @@ private static EntityMetadata FromSyntaxTree(SyntaxTree syntaxTree)
var result = new EntityMetadata();
result.Name = classNode.Identifier.Text;
- result.Namespace = namespaceNode.Name.ToString();
+
+ if (namespaceNode != null)
+ {
+ result.Namespace = namespaceNode.Name.ToString();
+ }
if (classNode.BaseList != null && classNode.BaseList.Types.Count > 0)
{
diff --git a/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/ClassWithoutNamespace.cs b/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/ClassWithoutNamespace.cs
new file mode 100644
index 0000000..7e9cd58
--- /dev/null
+++ b/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/ClassWithoutNamespace.cs
@@ -0,0 +1,4 @@
+class ClassWithoutNamespace
+{
+ public string PropertyStringName { get; set; }
+}
\ No newline at end of file
diff --git a/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/SampleCodeProvider.cs b/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/SampleCodeProvider.cs
index dc902a6..cf945e1 100644
--- a/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/SampleCodeProvider.cs
+++ b/src/DtoGenerator/DtoGenerator.Tests/CodeSamples/SampleCodeProvider.cs
@@ -21,7 +21,7 @@ public static class SampleCodeProvider
public static string EntityOnlySimpleProperties => GetManifestText(nameof(EntityOnlySimpleProperties));
public static string EntityOnlySimplePropertiesDto => GetManifestText(nameof(EntityOnlySimplePropertiesDto));
-
+
public static string EntityWithCollectionProperties => GetManifestText(nameof(EntityWithCollectionProperties));
public static string SampleTable1 => GetManifestText(nameof(SampleTable1));
@@ -30,6 +30,8 @@ public static class SampleCodeProvider
public static string NestedEntity => GetManifestText(nameof(NestedEntity));
+ public static string ClassWithoutNamespace => GetManifestTextWithFileStream(nameof(ClassWithoutNamespace));
+
private static string GetManifestText(string name)
{
using (var stream = typeof(SampleCodeProvider).Assembly.GetManifestResourceStream($"DtoGenerator.Tests.CodeSamples.{name}.cs"))
@@ -40,5 +42,16 @@ private static string GetManifestText(string name)
}
}
}
+
+ private static string GetManifestTextWithFileStream(string name)
+ {
+ using (var stream = new FileStream($@"../../CodeSamples/{name}.cs", FileMode.Open))
+ {
+ using (var reader = new StreamReader(stream))
+ {
+ return reader.ReadToEnd();
+ }
+ }
+ }
}
}
diff --git a/src/DtoGenerator/DtoGenerator.Tests/DtoGenerator.Tests.csproj b/src/DtoGenerator/DtoGenerator.Tests/DtoGenerator.Tests.csproj
index ad72fc7..4be98e0 100644
--- a/src/DtoGenerator/DtoGenerator.Tests/DtoGenerator.Tests.csproj
+++ b/src/DtoGenerator/DtoGenerator.Tests/DtoGenerator.Tests.csproj
@@ -118,6 +118,7 @@
+
diff --git a/src/DtoGenerator/DtoGenerator.Tests/EntityParserTest.cs b/src/DtoGenerator/DtoGenerator.Tests/EntityParserTest.cs
index d5ce41d..6b3929e 100644
--- a/src/DtoGenerator/DtoGenerator.Tests/EntityParserTest.cs
+++ b/src/DtoGenerator/DtoGenerator.Tests/EntityParserTest.cs
@@ -46,6 +46,16 @@ public void EntityParser_ParseEntity_SimplePropertiesOnly()
Assert.IsTrue(metadata.Properties.Any(p => p.Name == "OtherString" && p.IsSimpleProperty && p.Type == "string"));
}
+ [TestMethod]
+ public void EntityParser_ParseEntity_ClassWithoutNamespace()
+ {
+ var code = SampleCodeProvider.ClassWithoutNamespace;
+ var metadata = EntityParser.FromString(code);
+
+ Assert.IsTrue(metadata.Namespace == null);
+ Assert.IsTrue(metadata.Properties.Any(p => p.Name == "PropertyStringName" && p.IsSimpleProperty && p.Type == "string"));
+ }
+
[TestMethod]
public void EntityParser_ParseEntity_WithCollectionProperties()
{
diff --git a/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.cs b/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.cs
index bd6892b..33ebbdc 100644
--- a/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.cs
+++ b/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.cs
@@ -40,6 +40,7 @@ namespace DtoGenerator.Vsix
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(GenerateDtoCommandPackage.PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
+ [ProvideAutoLoad("{F1536EF8-92EC-443C-9ED7-FDADF150DA82}")] //value of VSConstants' SolutionExists property
public sealed class GenerateDtoCommandPackage : Package
{
///
diff --git a/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.vsct b/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.vsct
index 853d456..504f254 100644
--- a/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.vsct
+++ b/src/DtoGenerator/DtoGenerator.Vsix/GenerateDtoCommandPackage.vsct
@@ -39,6 +39,9 @@
+
@@ -55,6 +58,7 @@