Skip to content

Commit 9542abb

Browse files
authored
Featurres/continue code gen (#5)
* Move some stuff around and add gen projects * Basic test works. More needed.
1 parent 34caf62 commit 9542abb

File tree

142 files changed

+16341
-582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+16341
-582
lines changed

.editorconfig

Lines changed: 189 additions & 189 deletions
Large diffs are not rendered by default.

AStar.Dev.slnx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</Folder>
4040
<Folder Name="/src/modules/usage module/">
4141
<Project Path="src/nuget-packages/AStar.Dev.Api.Usage.Sdk/AStar.Dev.Api.Usage.Sdk.csproj" />
42-
<Project Path="src\nuget-packages\AStar.Dev.Usage.Api.Client.SDK\AStar.Dev.Usage.Api.Client.SDK.csproj" Type="C#" />
42+
<Project Path="src/nuget-packages/AStar.Dev.Usage.Api.Client.SDK/AStar.Dev.Usage.Api.Client.SDK.csproj" Type="C#" />
4343
</Folder>
4444
<Folder Name="/src/nuget-packages/">
4545
<Project Path="src/nuget-packages/AStar.Dev.Api.HealthChecks/AStar.Dev.Api.HealthChecks.csproj" />
@@ -63,8 +63,9 @@
6363
<Project Path="src/nuget-packages/AStar.Dev.Utilities/AStar.Dev.Utilities.csproj" />
6464
</Folder>
6565
<Folder Name="/src/source-generators/">
66-
<Project Path="src/source-generators/AStar.Dev.SourceGenerators/AStar.Dev.SourceGenerators.csproj" />
6766
<Project Path="src\source-generators\AStar.Dev.Annotations\AStar.Dev.Annotations.csproj" Type="Classic C#" />
67+
<Project Path="src\source-generators\AStar.Dev.Source.Generators\AStar.Dev.Source.Generators.csproj" Type="Classic C#" />
68+
<Project Path="src\source-generators\AStar.Dev.SourceGenerators.TestApp\AStar.Dev.SourceGenerators.TestApp.csproj" Type="Classic C#" />
6869
</Folder>
6970
<Folder Name="/src/uis/">
7071
<Project Path="src/uis/AStar.Dev.Web/AStar.Dev.Web.csproj" />
@@ -78,9 +79,9 @@
7879
<Project Path="test/AStar.Dev.Tests.Architecture/AStar.Dev.Tests.Architecture.csproj" />
7980
</Folder>
8081
<Folder Name="/test/modules/">
81-
<Project Path="test/modules/AStar.Dev.Database.Updater.Core.Tests.Unit/AStar.Dev.Database.Updater.Core.Tests.Unit.csproj" />
8282
<Project Path="test/modules/AStar.Dev.Database.Updater.Tests.Integration/AStar.Dev.Database.Updater.Tests.Integration.csproj" />
8383
<Project Path="test/modules/AStar.Dev.Database.Updater.Tests.Unit/AStar.Dev.Database.Updater.Tests.Unit.csproj" />
84+
<Project Path="test\modules\AStar.Dev.Database.Updater.Core.Tests.Integration\AStar.Dev.Database.Updater.Core.Tests.Integration.csproj" />
8485
</Folder>
8586
<Folder Name="/test/modules/apis/">
8687
<Project Path="test/modules/apis/AStar.Dev.Admin.Api.Tests.EndToEnd/AStar.Dev.Admin.Api.Tests.EndToEnd.csproj" />
@@ -113,6 +114,9 @@
113114
<Project Path="test/nuget-packages/AStar.Dev.Test.Helpers.Tests.Unit/AStar.Dev.Test.Helpers.Tests.Unit.csproj" />
114115
<Project Path="test/nuget-packages/AStar.Dev.Utilities.Tests.Unit/AStar.Dev.Utilities.Tests.Unit.csproj" />
115116
</Folder>
117+
<Folder Name="/test/source-generators/">
118+
<Project Path="test\source-generators\AStar.Dev.Source.Generators.Tests.Unit\AStar.Dev.Source.Generators.Test.Unit.csproj" Type="Classic C#" />
119+
</Folder>
116120
<Folder Name="/test/test-helpers/">
117121
<Project Path="test/test-helpers/AStar.Dev.TestHelpers/AStar.Dev.TestHelpers.csproj" />
118122
</Folder>

Directory.Build.props

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project>
2-
<PropertyGroup>
3-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4-
<TargetFramework>net9.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<ImplicitUsings>true</ImplicitUsings>
7-
</PropertyGroup>
2+
<PropertyGroup>
3+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>true</ImplicitUsings>
7+
</PropertyGroup>
88

9-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10-
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
11-
<NoWarn>1701;1702;</NoWarn>
12-
</PropertyGroup>
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
11+
<NoWarn>1701;1702;</NoWarn>
12+
</PropertyGroup>
1313

14-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
15-
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
16-
<NoWarn>1701;1702;</NoWarn>
17-
</PropertyGroup>
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
15+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
16+
<NoWarn>1701;1702;</NoWarn>
17+
</PropertyGroup>
1818
</Project>

src/nuget-packages/AStar.Dev.Infrastructure.FilesDb/AStar.Dev.Infrastructure.FilesDb.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<ItemGroup>
5858
<ProjectReference Include="..\..\source-generators\AStar.Dev.Annotations\AStar.Dev.Annotations.csproj" />
59-
<ProjectReference Include="..\..\source-generators\AStar.Dev.SourceGenerators\AStar.Dev.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
59+
<ProjectReference Include="..\..\source-generators\AStar.Dev.Source.Generators\AStar.Dev.Source.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
6060
<ProjectReference Include="..\AStar.Dev.Infrastructure\AStar.Dev.Infrastructure.csproj"/>
6161
<ProjectReference Include="..\AStar.Dev.Technical.Debt.Reporting\AStar.Dev.Technical.Debt.Reporting.csproj"/>
6262
<ProjectReference Include="..\AStar.Dev.Utilities\AStar.Dev.Utilities.csproj"/>
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>preview</LangVersion>
6-
<Nullable>enable</Nullable>
4+
<TargetFramework>net9.0</TargetFramework>
75
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
87
</PropertyGroup>
98

10-
</Project>
9+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AStar.Dev.Annotations;
2+
3+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
4+
public sealed class ConfigSectionAttribute(string name) : Attribute
5+
{
6+
public string Name { get; } = name;
7+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace AStar.Dev.Annotations;
2+
3+
public enum Lifetime
4+
{
5+
Singleton,
6+
Scoped,
7+
Transient
8+
}
9+
10+
/// <summary>
11+
/// An attribute used to register a class as a service within a dependency injection container.
12+
/// The attribute allows specifying the service's lifetime, the interface it should be registered against,
13+
/// and whether the concrete type should also be registered as itself.
14+
/// </summary>
15+
/// <param name="lifetime">The required lifetime of the service being registered</param>
16+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
17+
public sealed class RegisterServiceAttribute(Lifetime lifetime = Lifetime.Scoped) : Attribute
18+
{
19+
/// <summary>
20+
/// Specifies the lifetime of a service when registered in a dependency injection container.
21+
/// </summary>
22+
/// <remarks>
23+
/// Lifetime defines how the service is instantiated and shared within the application:
24+
/// - Singleton: A single instance is created and shared across the entire application.
25+
/// - Scoped: A single instance is created and shared within the same scope, such as a single HTTP request in web applications.
26+
/// - Transient: A new instance is created each time the service is requested.
27+
/// </remarks>
28+
public Lifetime Lifetime { get; } = lifetime;
29+
30+
/// <summary>
31+
/// Specifies the interface or base type that the service should be registered against
32+
/// within the dependency injection container.
33+
/// </summary>
34+
/// <remarks>
35+
/// This property allows for explicitly defining the type the service is associated with,
36+
/// enabling more control over how the service is resolved at runtime. If not specified,
37+
/// the default behavior may vary based on the DI container implementation.
38+
/// </remarks>
39+
public Type? As { get; set; }
40+
41+
/// <summary>
42+
/// Determines whether the concrete type of the service should be registered as itself
43+
/// in addition to any specified service interface.
44+
/// </summary>
45+
/// <remarks>
46+
/// If set to <c>true</c>, the concrete type will be registered in the dependency injection
47+
/// container so that it can be resolved directly. This is useful when the service
48+
/// needs to be resolved by its own type rather than an interface.
49+
/// </remarks>
50+
public bool AsSelf { get; set; } = false;
51+
}
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
1-
using System;
2-
31
namespace AStar.Dev.Annotations;
42

5-
/// <summary>
6-
/// Represents an attribute that can be used to mark a struct as a strong identifier.
7-
/// </summary>
8-
/// <remarks>
9-
/// This attribute is used to annotate structures with a specific identifier type, typically
10-
/// to signify that the struct is a strongly typed id. The default identifier type is a GUID.
11-
/// </remarks>
12-
/// <param name="idType">
13-
/// The type of the identifier associated with the struct. By default, it is "System.Guid".
14-
/// </param>
15-
/// <param name="guidV7">
16-
/// Indicates whether the GUID used as the identifier for the struct conforms to the version 7 GUID format.
17-
/// </param>
183
[AttributeUsage(AttributeTargets.Struct)]
19-
public sealed class StrongIdAttribute(string idType = "System.Guid", bool guidV7 = true) : Attribute
4+
public sealed class StrongIdAttribute(string underlying = "System.Guid") : Attribute
205
{
216
/// <summary>
22-
/// Gets the type of the identifier associated with a struct marked by the <see cref="StrongIdAttribute"/>.
23-
/// </summary>
24-
/// <remarks>
25-
/// This property returns the string name of the identifier type. By default, it is "System.Guid".
26-
/// The identifier type specifies the type used as an identifier for the struct.
27-
/// </remarks>
28-
public string IdType { get; } = idType;
29-
30-
/// <summary>
31-
/// Indicates whether the GUID used as the identifier for a struct marked by the <see cref="StrongIdAttribute"/>
32-
/// conforms to the version 7 GUID format.
7+
/// Underlying CLR type. Defaults to System.Guid.
8+
/// Examples: "System.Guid", "int", "long", "string".
339
/// </summary>
34-
/// <remarks>
35-
/// Version 7 GUIDs are designed to facilitate time-based sorting and are a newer standard
36-
/// compared to the traditional random GUIDs (version 4). When this property is set to true,
37-
/// the identifier adopts the version 7 format.
38-
/// </remarks>
39-
public bool GuidV7 { get; } = guidV7;
40-
}
10+
public string Underlying { get; } = underlying;
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
8+
<IsRoslynComponent>true</IsRoslynComponent>
9+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10+
<IncludeBuildOutput>false</IncludeBuildOutput>
11+
<NoWarn>$(NoWarn);NU5128</NoWarn>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
19+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0"/>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace AStar.Dev.Source.Generators;
2+
3+
/// <summary>
4+
/// Provides a centralized location for constant values used in the AStar.Dev.Source.Generators library.
5+
/// </summary>
6+
public static class Constants
7+
{
8+
/// <summary>
9+
/// Represents a predefined string indicating the namespace of the source generators within the AStar.Dev.Source.Generators library.
10+
/// </summary>
11+
public const string Namespace = "AStar.Dev.Source.Generators";
12+
13+
/// <summary>
14+
/// Represents a predefined string containing the header comment added to the top of generated source files,
15+
/// indicating that the file is auto-generated by the AStar.Dev.Source.Generators library and should not be manually edited.
16+
/// </summary>
17+
public const string SourceGeneratorHeader = $"""
18+
//----------------------
19+
// <auto-generated>
20+
// Generated by {Namespace}
21+
// Do not edit this file manually. Any changes will be overwritten at the next build.
22+
// </auto-generated>
23+
//----------------------
24+
""";
25+
26+
public const string GeneratedSourceXmlClassHeader = """
27+
/// <summary>
28+
/// Generated class header to quiet the compiler when XML Documentation is generated.
29+
/// This class contains the registration for services tagged with the RegisterService attribute.
30+
/// </summary>
31+
""";
32+
33+
public const string GeneratedSourceXmlHeader = """
34+
/// <summary>
35+
/// Generated method summary to quiet the compiler when XML Documentation is generated.
36+
/// </summary>
37+
""";
38+
}

0 commit comments

Comments
 (0)