Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ClassWithoutNamespace
{
public string PropertyStringName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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"))
Expand All @@ -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();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<EmbeddedResource Include="CodeSamples\EntityWithBase.cs" />
<EmbeddedResource Include="CodeSamples\EntityWithBaseDTO.cs" />
<EmbeddedResource Include="CodeSamples\NestedEntity.cs" />
<Compile Include="CodeSamples\ClassWithoutNamespace.cs" />
<Compile Include="CodeSamples\SampleCodeProvider.cs" />
<EmbeddedResource Include="CodeSamples\SampleTable1.cs" />
<EmbeddedResource Include="CodeSamples\SampleTable2.cs" />
Expand Down
10 changes: 10 additions & 0 deletions src/DtoGenerator/DtoGenerator.Tests/EntityParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<Group guid="guidGenerateDtoCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>
</Group>
<Group guid="guidGenerateDtoCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
</Group>
</Groups>

<!--Buttons section. -->
Expand All @@ -55,6 +58,7 @@
<Button guid="guidGenerateDtoCommandPackageCmdSet" id="GenerateDtoCommandId" priority="0x0100" type="Button">
<Parent guid="guidGenerateDtoCommandPackageCmdSet" id="MyMenuGroup" />
<Icon guid="guidImages" id="bmpPic1" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Generate DTO...</ButtonText>
</Strings>
Expand Down