Skip to content

Commit

Permalink
Merge pull request #7 from xaviersolau/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xaviersolau authored Apr 29, 2019
2 parents 72d6f1f + bcfa2cd commit 953f897
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ You can checkout this Github repository or you can use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.GeneratorTools.Core.CSharp -version 1.0.0-alpha.1
Install-Package SoloX.GeneratorTools.Core.CSharp -version 1.0.0-alpha.2
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.GeneratorTools.Core.CSharp --version 1.0.0-alpha.1
dotnet add package SoloX.GeneratorTools.Core.CSharp --version 1.0.0-alpha.2
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.GeneratorTools.Core.CSharp" Version="1.0.0-alpha.1" />
<PackageReference Include="SoloX.GeneratorTools.Core.CSharp" Version="1.0.0-alpha.2" />
```

## How to use it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ public EntityGeneratorExample(ILogger<EntityGeneratorExample> logger, ICSharpWor
/// Process the generator.
/// </summary>
/// <param name="projectFile">The project file to work from.</param>
/// <param name="projectNameSpace">The project name space.</param>
public void Generate(string projectFile, string projectNameSpace)
public void Generate(string projectFile)
{
this.logger.LogInformation($"Loading {Path.GetFileName(projectFile)}...");

var projectFolder = Path.GetDirectoryName(projectFile);

// First we need to register the project.
this.workspace.RegisterProject(projectFile);
var project = this.workspace.RegisterProject(projectFile);

// Register the pattern interface.
var patternInterfaceDeclaration = this.workspace.RegisterFile("./Patterns/Itf/IEntityPattern.cs")
Expand All @@ -71,7 +70,7 @@ public void Generate(string projectFile, string projectNameSpace)
var entityBaseInterface = resolver.Find("SoloX.GeneratorTools.Core.CSharp.Examples.Core.IEntityBase").Single() as IGenericDeclaration;

// Setup a locator that will tell the location where the generated classes must be written.
var locator = new RelativeLocator(projectFolder, projectNameSpace, suffix: "Impl");
var locator = new RelativeLocator(projectFolder, project.RootNameSpace, suffix: "Impl");

// Create the Implementation Generator with a file generator, the locator and the pattern interface/class.
var generator = new ImplementationGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ public ModelGeneratorExample(ILogger<ModelGeneratorExample> logger, ICSharpWorks
/// Process the generator.
/// </summary>
/// <param name="projectFile">The project file to work from.</param>
/// <param name="projectNameSpace">The project name space.</param>
public void Generate(string projectFile, string projectNameSpace)
public void Generate(string projectFile)
{
this.logger.LogInformation($"Loading {Path.GetFileName(projectFile)}...");

var projectFolder = Path.GetDirectoryName(projectFile);

// First we need to register the project.
this.workspace.RegisterProject(projectFile);
var project = this.workspace.RegisterProject(projectFile);

// Register the pattern interface.
var patternInterfaceDeclaration = this.workspace.RegisterFile("./Patterns/Itf/IModelPattern.cs")
Expand All @@ -71,7 +70,7 @@ public void Generate(string projectFile, string projectNameSpace)
var modelBaseInterface = resolver.Find("SoloX.GeneratorTools.Core.CSharp.Examples.Core.IModelBase").Single() as IGenericDeclaration;

// Setup a locator that will tell the location where the generated classes must be written.
var locator = new RelativeLocator(projectFolder, projectNameSpace, suffix: "Impl");
var locator = new RelativeLocator(projectFolder, project.RootNameSpace, suffix: "Impl");

// Create the Implementation Generator with a file generator, the locator and the pattern interface/class.
var generator = new ImplementationGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ private void Run()
var prjFolder = "../../../../SoloX.GeneratorTools.Core.CSharp.Examples.Sample";
var prjFile = Path.Combine(prjFolder, "SoloX.GeneratorTools.Core.CSharp.Examples.Sample.csproj");

// Set the project default namespace.
var projectNameSpace = "SoloX.GeneratorTools.Core.CSharp.Examples.Sample";

// Get the entity generator example and generate the entity implementations in the given C# project.
this.Service.GetService<EntityGeneratorExample>().Generate(prjFile, projectNameSpace);
this.Service.GetService<EntityGeneratorExample>().Generate(prjFile);

// Get the model generator example and generate the model implementations in the given C# project.
this.Service.GetService<ModelGeneratorExample>().Generate(prjFile, projectNameSpace);
this.Service.GetService<ModelGeneratorExample>().Generate(prjFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<Target Name="ProjectRootNameSpace">
<Message Importance="high" Text="$(RootNamespace)" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<PackageId>SoloX.GeneratorTools.Core.CSharp</PackageId>

<Version>1.0.0-alpha.1</Version>
<Version>1.0.0-alpha.2</Version>
<Authors>Xavier Solau</Authors>
<Copyright>Copyright © 2019 Xavier Solau</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/xaviersolau/GeneratorTools/master/LICENSE</PackageLicenseUrl>
Expand All @@ -24,16 +24,18 @@
<None Remove="Resources\Workspace\CompileList.targets" />
<None Remove="Resources\Workspace\PackageReferenceList.targets" />
<None Remove="Resources\Workspace\ProjectReferenceList.targets" />
<None Remove="Resources\Workspace\ProjectRootNameSpace.targets" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Workspace\PackageReferenceList.targets" />
<EmbeddedResource Include="Resources\Workspace\ProjectRootNameSpace.targets" />
<EmbeddedResource Include="Resources\Workspace\ProjectReferenceList.targets" />
<EmbeddedResource Include="Resources\Workspace\CompileList.targets" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public interface ICSharpProject
/// </summary>
string ProjectPath { get; }

/// <summary>
/// Gets the project root name space.
/// </summary>
string RootNameSpace { get; }

/// <summary>
/// Gets the project references.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class CSharpProject : ICSharpProject
{
private const string CompileList = "CompileList";
private const string ProjectReferenceList = "ProjectReferenceList";
private const string ProjectRootNameSpace = "ProjectRootNameSpace";

private const string DotNet = "dotnet";

Expand All @@ -48,6 +49,9 @@ public CSharpProject(string file)
/// <inheritdoc/>
public string ProjectPath { get; }

/// <inheritdoc/>
public string RootNameSpace { get; private set; }

/// <inheritdoc/>
public IReadOnlyCollection<ICSharpProject> ProjectReferences { get; private set; }

Expand All @@ -67,6 +71,9 @@ public void Load(ICSharpWorkspace workspace)

this.isLoaded = true;

// Get the project root name space
this.RootNameSpace = this.DeployAndRunTarget(ProjectRootNameSpace).Trim();

// Get the project references.
var projectReferenceList = this.DeployAndRunTarget(ProjectReferenceList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<PackageId>SoloX.GeneratorTools.Core</PackageId>

<Version>1.0.0-alpha.1</Version>
<Version>1.0.0-alpha.2</Version>
<Authors>Xavier Solau</Authors>
<Copyright>Copyright © 2019 Xavier Solau</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/xaviersolau/GeneratorTools/master/LICENSE</PackageLicenseUrl>
Expand All @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Prod" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public void LoadCSharpProjectTest()

var csFile = project.Files.Single();
Assert.Equal("Sample2Class1.cs", csFile.FileName);

var ns = project.RootNameSpace;
Assert.Equal("SoloX.GeneratorTools.Core.CSharp.Sample2", ns);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0-rc.4" />
<PackageReference Include="SoloX.CodeQuality.Test" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down

0 comments on commit 953f897

Please sign in to comment.