Skip to content

Commit 63d6de0

Browse files
authored
Fundamental redesign to allow complete customisation (#117)
* Use ForAttributeWithMetadataName APIs Fix duplicate test problem Add new diagnostic for duplicate assembly attributes * wip * wip * Add long and .net 8 support * Add string (and fix bugs) * Add Nullable String * Add NewId template * Update snapshots * Lots of fixes * Fix packaging (and remove other package) * Delete old files * Remove unused diagnostics * Add invalid template name diagnostic * Update handling of unknown templates (adds a diagnostic) * Don't do special behaviour for custom templates + add diagnostic for invalid templates * Add codefixprovider (need to try it) * Fix nullability warning * Make the analyzer return an error instead * Revert accidental hacking aroudn * Make nullable ID an extended type * Move to separate templates NuGet folder * Add some optional "partial" templates * Try to fix tests * Remove the built-in templates from the generator tests They just add noise * Support adding multiple templates in one attribute * Add unit tests for multiple templates * Fix StringBuilder re-use bug * Add missing templates * Add guid converter templates tests * Add LongId tests * Add string integration tests * Fix typos * Update diagnostics to ensure unique (breaking change) * Remove unused includes * Fix templates package * Show the additional templates in the project * Add 8.0.x to Github actions * Tweak codefix action * Fix windows-specific paths * Ensure we test both in-project IDs and "external" IDs * Make all the converts public by default It doesn't really make sense that their not... * Add source generator tests for GuidIds * Use Ordinal Comparisons instead of culture-specific in string IDs * Add test for the nullable * Make all converters partial * Add comparison operators * Fix typo
1 parent 69473c3 commit 63d6de0

File tree

225 files changed

+10226
-12031
lines changed

Some content is hidden

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

225 files changed

+10226
-12031
lines changed

.github/workflows/BuildAndPack.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- uses: actions/setup-dotnet@v3
3737
with:
3838
dotnet-version: |
39+
8.0.x
3940
7.0.x
4041
6.0.x
4142
5.0.x
@@ -66,6 +67,7 @@ jobs:
6667
- uses: actions/setup-dotnet@v3
6768
with:
6869
dotnet-version: |
70+
8.0.x
6971
7.0.x
7072
6.0.x
7173
5.0.x
@@ -96,6 +98,7 @@ jobs:
9698
- uses: actions/setup-dotnet@v3
9799
with:
98100
dotnet-version: |
101+
8.0.x
99102
7.0.x
100103
6.0.x
101104
5.0.x

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,6 @@ ModelManifest.xml
245245
.fake/
246246
tools/*
247247
!tools/packages.config
248+
249+
# NuGet testing
250+
globalPackagesFolder

NuGet.integration-tests.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3+
<config>
4+
<add key="globalPackagesFolder" value="globalPackagesFolder" />
5+
</config>
36
<packageSources>
47
<clear />
58
<add key="local-packages" value="./artifacts" />
69
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
710
</packageSources>
11+
<packageSourceMapping>
12+
<packageSource key="nuget">
13+
<package pattern="*" />
14+
</packageSource>
15+
<packageSource key="local-packages">
16+
<package pattern="StronglyTypedId" />
17+
<package pattern="StronglyTypedId.*" />
18+
</packageSource>
19+
</packageSourceMapping>
820
</configuration>

StronglyTypedId.sln

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Nuget.Inte
3232
EndProject
3333
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Nuget.Attributes.IntegrationTests", "test\StronglyTypedIds.Nuget.Attributes.IntegrationTests\StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj", "{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}"
3434
EndProject
35+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Templates", "src\StronglyTypedIds.Templates\StronglyTypedIds.Templates.csproj", "{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}"
36+
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.IntegrationTests.Types", "test\StronglyTypedIds.IntegrationTests.Types\StronglyTypedIds.IntegrationTests.Types.csproj", "{A5804404-E5A5-4F05-86E2-B2A11D370498}"
38+
EndProject
39+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.IntegrationTests.ExternalIds", "test\StronglyTypedIds.IntegrationTests.ExternalIds\StronglyTypedIds.IntegrationTests.ExternalIds.csproj", "{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}"
40+
EndProject
3541
Global
3642
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3743
Debug|Any CPU = Debug|Any CPU
@@ -104,6 +110,42 @@ Global
104110
{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Release|Any CPU.ActiveCfg = Release|Any CPU
105111
{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Release|x64.ActiveCfg = Release|Any CPU
106112
{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Release|x86.ActiveCfg = Release|Any CPU
113+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
114+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
115+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Debug|x64.ActiveCfg = Debug|Any CPU
116+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Debug|x64.Build.0 = Debug|Any CPU
117+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Debug|x86.ActiveCfg = Debug|Any CPU
118+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Debug|x86.Build.0 = Debug|Any CPU
119+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
120+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Release|Any CPU.Build.0 = Release|Any CPU
121+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Release|x64.ActiveCfg = Release|Any CPU
122+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Release|x64.Build.0 = Release|Any CPU
123+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Release|x86.ActiveCfg = Release|Any CPU
124+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C}.Release|x86.Build.0 = Release|Any CPU
125+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Debug|Any CPU.Build.0 = Debug|Any CPU
127+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Debug|x64.ActiveCfg = Debug|Any CPU
128+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Debug|x64.Build.0 = Debug|Any CPU
129+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Debug|x86.ActiveCfg = Debug|Any CPU
130+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Debug|x86.Build.0 = Debug|Any CPU
131+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Release|Any CPU.ActiveCfg = Release|Any CPU
132+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Release|Any CPU.Build.0 = Release|Any CPU
133+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Release|x64.ActiveCfg = Release|Any CPU
134+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Release|x64.Build.0 = Release|Any CPU
135+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Release|x86.ActiveCfg = Release|Any CPU
136+
{A5804404-E5A5-4F05-86E2-B2A11D370498}.Release|x86.Build.0 = Release|Any CPU
137+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
138+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Debug|Any CPU.Build.0 = Debug|Any CPU
139+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Debug|x64.ActiveCfg = Debug|Any CPU
140+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Debug|x64.Build.0 = Debug|Any CPU
141+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Debug|x86.ActiveCfg = Debug|Any CPU
142+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Debug|x86.Build.0 = Debug|Any CPU
143+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Release|Any CPU.ActiveCfg = Release|Any CPU
144+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Release|Any CPU.Build.0 = Release|Any CPU
145+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Release|x64.ActiveCfg = Release|Any CPU
146+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Release|x64.Build.0 = Release|Any CPU
147+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Release|x86.ActiveCfg = Release|Any CPU
148+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047}.Release|x86.Build.0 = Release|Any CPU
107149
EndGlobalSection
108150
GlobalSection(SolutionProperties) = preSolution
109151
HideSolutionNode = FALSE
@@ -115,6 +157,9 @@ Global
115157
{F25F6E67-E62A-4075-86CF-4C4EDD7E4883} = {EE1258BD-3422-4F55-B9CF-B4D6C95DAD68}
116158
{A7355210-7DDC-4968-84B7-79002113EA6E} = {D1907D86-8FFC-4178-A3DB-0ADBDD282C64}
117159
{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23} = {D1907D86-8FFC-4178-A3DB-0ADBDD282C64}
160+
{336D7EE4-90BA-4BFC-99F6-D70B8D494E8C} = {EE1258BD-3422-4F55-B9CF-B4D6C95DAD68}
161+
{A5804404-E5A5-4F05-86E2-B2A11D370498} = {D1907D86-8FFC-4178-A3DB-0ADBDD282C64}
162+
{07875BB0-EFEE-4F90-AAB8-4B11F78C8047} = {D1907D86-8FFC-4178-A3DB-0ADBDD282C64}
118163
EndGlobalSection
119164
GlobalSection(ExtensibilityGlobals) = postSolution
120165
SolutionGuid = {8D1F0534-B8AD-4CFA-9C14-CBC757BCB1E1}
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
1-
using System;
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by the StronglyTypedId source generator
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#pragma warning disable 1591 // publicly visible type or member must be documented
11+
12+
#nullable enable
213

314
namespace StronglyTypedIds
415
{
516
/// <summary>
617
/// Place on partial structs to make the type a strongly-typed ID
718
/// </summary>
8-
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
9-
[System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")]
10-
public sealed class StronglyTypedIdAttribute : Attribute
19+
[global::System.AttributeUsage(global::System.AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
20+
[global::System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")]
21+
public sealed class StronglyTypedIdAttribute : global::System.Attribute
1122
{
1223
/// <summary>
13-
/// Make the struct a strongly typed ID
24+
/// Make the struct a strongly typed ID.
1425
/// </summary>
15-
/// <param name="backingType">The <see cref="Type"/> to use to store the strongly-typed ID value.
16-
/// If not set, uses <see cref="StronglyTypedIdDefaultsAttribute.BackingType"/>, which defaults to <see cref="StronglyTypedIdBackingType.Guid"/></param>
17-
/// <param name="converters">Converters to create for serializing/deserializing the strongly-typed ID value.
18-
/// If not set, uses <see cref="StronglyTypedIdDefaultsAttribute.Converters"/>, which defaults to <see cref="StronglyTypedIdConverter.NewtonsoftJson"/>
19-
/// and <see cref="StronglyTypedIdConverter.TypeConverter"/></param>
20-
/// <param name="implementations">Interfaces and patterns the strongly typed id should implement
21-
/// If not set, uses <see cref="StronglyTypedIdDefaultsAttribute.Implementations"/>, which defaults to <see cref="StronglyTypedIdImplementations.IEquatable"/>
22-
/// and <see cref="StronglyTypedIdImplementations.IComparable"/></param>
23-
public StronglyTypedIdAttribute(
24-
StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default,
25-
StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default,
26-
StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default)
26+
/// <param name="template">The built-in template to use to generate the ID.</param>
27+
/// <param name="templateNames">The names of additional custom templates to use to generate the ID.
28+
/// Templates must be added to the project using the format NAME.typedid,
29+
/// where NAME is the name of the template passed in <paramref name="templateNames"/>.
30+
/// </param>
31+
public StronglyTypedIdAttribute(global::StronglyTypedIds.Template template, params string[] templateNames)
2732
{
28-
BackingType = backingType;
29-
Converters = converters;
30-
Implementations = implementations;
3133
}
3234

3335
/// <summary>
34-
/// The <see cref="Type"/> to use to store the strongly-typed ID value
35-
/// </summary>
36-
public StronglyTypedIdBackingType BackingType { get; }
37-
38-
/// <summary>
39-
/// JSON library used to serialize/deserialize strongly-typed ID value
36+
/// Make the struct a strongly typed ID.
4037
/// </summary>
41-
public StronglyTypedIdConverter Converters { get; }
42-
43-
/// <summary>
44-
/// Interfaces and patterns the strongly typed id should implement
45-
/// </summary>
46-
public StronglyTypedIdImplementations Implementations { get; }
38+
/// <param name="templateNames">The names of the template to use to generate the ID.
39+
/// Templates must be added to the project using the format NAME.typedid,
40+
/// where NAME is the name of the template passed in <paramref name="templateNames"/>.
41+
/// If no templates are provided, the default value is used, as specified by
42+
/// <see cref="StronglyTypedIdDefaultsAttribute"/>, or alternatively the
43+
/// <see cref="Template.Guid"/> template.
44+
/// </param>
45+
public StronglyTypedIdAttribute(params string[] templateNames)
46+
{
47+
}
4748
}
4849
}

src/StronglyTypedIds.Attributes/StronglyTypedIdBackingType.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
1-
using System;
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by the StronglyTypedId source generator
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#pragma warning disable 1591 // publicly visible type or member must be documented
11+
12+
#nullable enable
213

314
namespace StronglyTypedIds
415
{
516
/// <summary>
6-
/// Used to control the default Place on partial structs to make the type a strongly-typed ID
17+
/// Used to control the default strongly typed ID values. Apply to an assembly using
18+
/// <code>[assembly:StronglyTypedIdDefaults(Template.Int)]</code> for example
719
/// </summary>
8-
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
9-
[System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")]
10-
public sealed class StronglyTypedIdDefaultsAttribute : Attribute
20+
[global::System.AttributeUsage(global::System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
21+
[global::System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")]
22+
public sealed class StronglyTypedIdDefaultsAttribute : global::System.Attribute
1123
{
1224
/// <summary>
13-
/// Set the default values used for strongly typed ids
25+
/// Set the default template to use for strongly typed IDs
1426
/// </summary>
15-
/// <param name="backingType">The <see cref="Type"/> to use to store the strongly-typed ID value.
16-
/// Defaults to <see cref="StronglyTypedIdBackingType.Guid"/></param>
17-
/// <param name="converters">JSON library used to serialize/deserialize strongly-typed ID value.
18-
/// Defaults to <see cref="StronglyTypedIdConverter.NewtonsoftJson"/> and <see cref="StronglyTypedIdConverter.TypeConverter"/></param>
19-
/// <param name="implementations">Interfaces and patterns the strongly typed id should implement
20-
/// Defaults to <see cref="StronglyTypedIdImplementations.IEquatable"/> and <see cref="StronglyTypedIdImplementations.IComparable"/></param>
21-
public StronglyTypedIdDefaultsAttribute(
22-
StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default,
23-
StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default,
24-
StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default)
27+
/// <param name="template">The built-in template to use to generate the ID.</param>
28+
/// <param name="templateNames">The names of additional custom templates to use to generate the ID.
29+
/// Templates must be added to the project using the format NAME.typedid,
30+
/// where NAME is the name of the template passed in <paramref name="templateNames"/>.
31+
/// </param>
32+
public StronglyTypedIdDefaultsAttribute(global::StronglyTypedIds.Template template, params string[] templateNames)
2533
{
26-
BackingType = backingType;
27-
Converters = converters;
28-
Implementations = implementations;
2934
}
3035

3136
/// <summary>
32-
/// The default <see cref="Type"/> to use to store the strongly-typed ID values.
33-
/// </summary>
34-
public StronglyTypedIdBackingType BackingType { get; }
35-
36-
/// <summary>
37-
/// The default converters to create for serializing/deserializing strongly-typed ID values.
37+
/// Set the default template to use for strongly typed IDs
3838
/// </summary>
39-
public StronglyTypedIdConverter Converters { get; }
39+
/// <param name="templateName">The name of the template to use to generate the ID.
40+
/// Templates must be added to the project using the format NAME.typedid,
41+
/// where NAME is the name of the template passed in <paramref name="templateName"/>.
42+
/// </param>
43+
public StronglyTypedIdDefaultsAttribute(string templateName)
44+
{
45+
}
4046

4147
/// <summary>
42-
/// Interfaces and patterns the strongly typed id should implement
48+
/// Set the default template to use for strongly typed IDs
4349
/// </summary>
44-
public StronglyTypedIdImplementations Implementations { get; }
50+
/// <param name="templateName">The name of the template to use to generate the ID.
51+
/// Templates must be added to the project using the format NAME.typedid,
52+
/// where NAME is the name of the template passed in <paramref name="templateName"/>.
53+
/// </param>
54+
public StronglyTypedIdDefaultsAttribute(string templateName, params string[] templateNames)
55+
{
56+
}
4557
}
4658
}

0 commit comments

Comments
 (0)