-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
69473c3
commit 63d6de0
Showing
225 changed files
with
10,226 additions
and
12,031 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,3 +245,6 @@ ModelManifest.xml | |
.fake/ | ||
tools/* | ||
!tools/packages.config | ||
|
||
# NuGet testing | ||
globalPackagesFolder |
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 |
---|---|---|
@@ -1,8 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<config> | ||
<add key="globalPackagesFolder" value="globalPackagesFolder" /> | ||
</config> | ||
<packageSources> | ||
<clear /> | ||
<add key="local-packages" value="./artifacts" /> | ||
<add key="nuget" value="https://api.nuget.org/v3/index.json" /> | ||
</packageSources> | ||
<packageSourceMapping> | ||
<packageSource key="nuget"> | ||
<package pattern="*" /> | ||
</packageSource> | ||
<packageSource key="local-packages"> | ||
<package pattern="StronglyTypedId" /> | ||
<package pattern="StronglyTypedId.*" /> | ||
</packageSource> | ||
</packageSourceMapping> | ||
</configuration> |
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
65 changes: 33 additions & 32 deletions
65
src/StronglyTypedIds.Attributes/StronglyTypedIdAttribute.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 |
---|---|---|
@@ -1,48 +1,49 @@ | ||
using System; | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by the StronglyTypedId source generator | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#pragma warning disable 1591 // publicly visible type or member must be documented | ||
|
||
#nullable enable | ||
|
||
namespace StronglyTypedIds | ||
{ | ||
/// <summary> | ||
/// Place on partial structs to make the type a strongly-typed ID | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] | ||
[System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] | ||
public sealed class StronglyTypedIdAttribute : Attribute | ||
[global::System.AttributeUsage(global::System.AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] | ||
[global::System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] | ||
public sealed class StronglyTypedIdAttribute : global::System.Attribute | ||
{ | ||
/// <summary> | ||
/// Make the struct a strongly typed ID | ||
/// Make the struct a strongly typed ID. | ||
/// </summary> | ||
/// <param name="backingType">The <see cref="Type"/> to use to store the strongly-typed ID value. | ||
/// If not set, uses <see cref="StronglyTypedIdDefaultsAttribute.BackingType"/>, which defaults to <see cref="StronglyTypedIdBackingType.Guid"/></param> | ||
/// <param name="converters">Converters to create for serializing/deserializing the strongly-typed ID value. | ||
/// If not set, uses <see cref="StronglyTypedIdDefaultsAttribute.Converters"/>, which defaults to <see cref="StronglyTypedIdConverter.NewtonsoftJson"/> | ||
/// and <see cref="StronglyTypedIdConverter.TypeConverter"/></param> | ||
/// <param name="implementations">Interfaces and patterns the strongly typed id should implement | ||
/// If not set, uses <see cref="StronglyTypedIdDefaultsAttribute.Implementations"/>, which defaults to <see cref="StronglyTypedIdImplementations.IEquatable"/> | ||
/// and <see cref="StronglyTypedIdImplementations.IComparable"/></param> | ||
public StronglyTypedIdAttribute( | ||
StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, | ||
StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, | ||
StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) | ||
/// <param name="template">The built-in template to use to generate the ID.</param> | ||
/// <param name="templateNames">The names of additional custom templates to use to generate the ID. | ||
/// Templates must be added to the project using the format NAME.typedid, | ||
/// where NAME is the name of the template passed in <paramref name="templateNames"/>. | ||
/// </param> | ||
public StronglyTypedIdAttribute(global::StronglyTypedIds.Template template, params string[] templateNames) | ||
{ | ||
BackingType = backingType; | ||
Converters = converters; | ||
Implementations = implementations; | ||
} | ||
|
||
/// <summary> | ||
/// The <see cref="Type"/> to use to store the strongly-typed ID value | ||
/// </summary> | ||
public StronglyTypedIdBackingType BackingType { get; } | ||
|
||
/// <summary> | ||
/// JSON library used to serialize/deserialize strongly-typed ID value | ||
/// Make the struct a strongly typed ID. | ||
/// </summary> | ||
public StronglyTypedIdConverter Converters { get; } | ||
|
||
/// <summary> | ||
/// Interfaces and patterns the strongly typed id should implement | ||
/// </summary> | ||
public StronglyTypedIdImplementations Implementations { get; } | ||
/// <param name="templateNames">The names of the template to use to generate the ID. | ||
/// Templates must be added to the project using the format NAME.typedid, | ||
/// where NAME is the name of the template passed in <paramref name="templateNames"/>. | ||
/// If no templates are provided, the default value is used, as specified by | ||
/// <see cref="StronglyTypedIdDefaultsAttribute"/>, or alternatively the | ||
/// <see cref="Template.Guid"/> template. | ||
/// </param> | ||
public StronglyTypedIdAttribute(params string[] templateNames) | ||
{ | ||
} | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
src/StronglyTypedIds.Attributes/StronglyTypedIdBackingType.cs
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs
This file was deleted.
Oops, something went wrong.
68 changes: 40 additions & 28 deletions
68
src/StronglyTypedIds.Attributes/StronglyTypedIdDefaultsAttribute.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 |
---|---|---|
@@ -1,46 +1,58 @@ | ||
using System; | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by the StronglyTypedId source generator | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#pragma warning disable 1591 // publicly visible type or member must be documented | ||
|
||
#nullable enable | ||
|
||
namespace StronglyTypedIds | ||
{ | ||
/// <summary> | ||
/// Used to control the default Place on partial structs to make the type a strongly-typed ID | ||
/// Used to control the default strongly typed ID values. Apply to an assembly using | ||
/// <code>[assembly:StronglyTypedIdDefaults(Template.Int)]</code> for example | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] | ||
[System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] | ||
public sealed class StronglyTypedIdDefaultsAttribute : Attribute | ||
[global::System.AttributeUsage(global::System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] | ||
[global::System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] | ||
public sealed class StronglyTypedIdDefaultsAttribute : global::System.Attribute | ||
{ | ||
/// <summary> | ||
/// Set the default values used for strongly typed ids | ||
/// Set the default template to use for strongly typed IDs | ||
/// </summary> | ||
/// <param name="backingType">The <see cref="Type"/> to use to store the strongly-typed ID value. | ||
/// Defaults to <see cref="StronglyTypedIdBackingType.Guid"/></param> | ||
/// <param name="converters">JSON library used to serialize/deserialize strongly-typed ID value. | ||
/// Defaults to <see cref="StronglyTypedIdConverter.NewtonsoftJson"/> and <see cref="StronglyTypedIdConverter.TypeConverter"/></param> | ||
/// <param name="implementations">Interfaces and patterns the strongly typed id should implement | ||
/// Defaults to <see cref="StronglyTypedIdImplementations.IEquatable"/> and <see cref="StronglyTypedIdImplementations.IComparable"/></param> | ||
public StronglyTypedIdDefaultsAttribute( | ||
StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, | ||
StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, | ||
StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) | ||
/// <param name="template">The built-in template to use to generate the ID.</param> | ||
/// <param name="templateNames">The names of additional custom templates to use to generate the ID. | ||
/// Templates must be added to the project using the format NAME.typedid, | ||
/// where NAME is the name of the template passed in <paramref name="templateNames"/>. | ||
/// </param> | ||
public StronglyTypedIdDefaultsAttribute(global::StronglyTypedIds.Template template, params string[] templateNames) | ||
{ | ||
BackingType = backingType; | ||
Converters = converters; | ||
Implementations = implementations; | ||
} | ||
|
||
/// <summary> | ||
/// The default <see cref="Type"/> to use to store the strongly-typed ID values. | ||
/// </summary> | ||
public StronglyTypedIdBackingType BackingType { get; } | ||
|
||
/// <summary> | ||
/// The default converters to create for serializing/deserializing strongly-typed ID values. | ||
/// Set the default template to use for strongly typed IDs | ||
/// </summary> | ||
public StronglyTypedIdConverter Converters { get; } | ||
/// <param name="templateName">The name of the template to use to generate the ID. | ||
/// Templates must be added to the project using the format NAME.typedid, | ||
/// where NAME is the name of the template passed in <paramref name="templateName"/>. | ||
/// </param> | ||
public StronglyTypedIdDefaultsAttribute(string templateName) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Interfaces and patterns the strongly typed id should implement | ||
/// Set the default template to use for strongly typed IDs | ||
/// </summary> | ||
public StronglyTypedIdImplementations Implementations { get; } | ||
/// <param name="templateName">The name of the template to use to generate the ID. | ||
/// Templates must be added to the project using the format NAME.typedid, | ||
/// where NAME is the name of the template passed in <paramref name="templateName"/>. | ||
/// </param> | ||
public StronglyTypedIdDefaultsAttribute(string templateName, params string[] templateNames) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.