-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved out code generation logic into the shared project
- Loading branch information
Showing
22 changed files
with
224 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
src/CoreCraft.Generators/CoreCraft.Generators.AssemblyInfo.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/CoreCraft.SourceGeneration/CoreCraft.SourceGeneration.projitems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<HasSharedItems>true</HasSharedItems> | ||
<SharedGUID>b11d3e00-59b5-4227-ab86-2f20e5fa330b</SharedGUID> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration"> | ||
<Import_RootNamespace>CoreCraft.SourceGeneration</Import_RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IndentedTextWriterExtensions.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Generators\EntitiesGenerator.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Generators\GeneratorCommon.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)generators\ModelGenerator.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Generators\ModelShardGenerator.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)ModelScheme.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Serialization\DtoConverter.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)serialization\ModelSchemeReader.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Serialization\ModelSchemeDto.cs" /> | ||
</ItemGroup> | ||
</Project> |
13 changes: 13 additions & 0 deletions
13
src/CoreCraft.SourceGeneration/CoreCraft.SourceGeneration.shproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>b11d3e00-59b5-4227-ab86-2f20e5fa330b</ProjectGuid> | ||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" /> | ||
<PropertyGroup /> | ||
<Import Project="CoreCraft.SourceGeneration.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/CoreCraft.SourceGeneration/Generators/GeneratorCommon.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace CoreCraft.SourceGeneration.Generators; | ||
|
||
internal abstract class GeneratorCommon | ||
{ | ||
protected static string DefineProperty(string type, string name, string accessors = "get; private set;") | ||
{ | ||
return string.Join(" ", type, name, "{", accessors, "}").Trim(); | ||
} | ||
|
||
protected static string ToCamelCase(string value) | ||
{ | ||
if (value.Length > 1) | ||
{ | ||
return $"{char.ToLower(value[0])}{value.Substring(1)}"; | ||
} | ||
|
||
return value; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/CoreCraft.SourceGeneration/Generators/ModelGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using CoreCraft.SourceGeneration.Extensions; | ||
|
||
namespace CoreCraft.SourceGeneration.Generators; | ||
|
||
internal static class ModelGenerator | ||
{ | ||
public static string Generate(string assemblyName, string modelName, ModelScheme modelScheme) | ||
{ | ||
var @namespace = $"{assemblyName}.{modelName}"; | ||
using var writer = new StringWriter(); | ||
using var code = new IndentedTextWriter(writer, " "); | ||
|
||
code.Preamble(); | ||
|
||
code.WriteLine($"namespace {@namespace}"); | ||
code.Block(() => | ||
{ | ||
code.WriteLine("using CoreCraft.Core;"); | ||
code.WriteLine("using CoreCraft.ChangesTracking;"); | ||
code.WriteLine("using CoreCraft.Persistence;"); | ||
code.WriteLine($"using {@namespace}.Entities;"); | ||
code.EmptyLine(); | ||
new ModelShardGenerator(code).Generate(modelScheme.Shards); | ||
}); | ||
code.EmptyLine(); | ||
|
||
code.WriteLine($"namespace {@namespace}.Entities"); | ||
code.Block(() => | ||
{ | ||
new EntitiesGenerator(code).Generate(modelScheme.Shards); | ||
}); | ||
|
||
return writer.ToString(); | ||
} | ||
} |
Oops, something went wrong.