Skip to content

Commit c04d570

Browse files
committed
Wrappers no longer generated parameterized ctor if any exist.
1 parent 103ef01 commit c04d570

6 files changed

Lines changed: 20 additions & 13 deletions

File tree

DomainModeling.Generator/IdentityGenerator.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ private static bool FilterSyntaxNode(SyntaxNode node, CancellationToken cancella
296296

297297
existingComponents |= IdTypeComponents.UnsettableValue.If(members.Any(member => member.Name == "Value" && member is not IFieldSymbol && member is not IPropertySymbol { SetMethod: not null }));
298298

299-
existingComponents |= IdTypeComponents.Constructor.If(type.InstanceConstructors.Any(ctor =>
300-
ctor.Parameters.Length >= 1 && (ctor.Parameters.Length is 1 || ctor.Parameters[1].HasExplicitDefaultValue) && // Callable with exactly 1 parameter
301-
ctor.Parameters[0].Type.Equals(underlyingType, SymbolEqualityComparer.Default)));
299+
existingComponents |= IdTypeComponents.Constructor.If(type.InstanceConstructors.Any(ctor => ctor is { Parameters.Length: >= 1, DeclaringSyntaxReferences.Length: > 0, }));
302300

303301
// Records override this, but our implementation is superior
304302
existingComponents |= IdTypeComponents.ToStringOverride.If(members.Any(member =>

DomainModeling.Generator/WrapperValueObjectGenerator.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ private static bool FilterSyntaxNode(SyntaxNode node, CancellationToken cancella
192192

193193
existingComponents |= WrapperValueObjectTypeComponents.UnsettableValue.If(members.Any(member => member.Name == "Value" && member is not IFieldSymbol && member is not IPropertySymbol { SetMethod: not null }));
194194

195-
existingComponents |= WrapperValueObjectTypeComponents.Constructor.If(type.InstanceConstructors.Any(ctor =>
196-
ctor.Parameters.Length >= 1 && (ctor.Parameters.Length is 1 || ctor.Parameters[1].HasExplicitDefaultValue) && // Callable with exactly 1 parameter
197-
ctor.Parameters[0].Type.Equals(underlyingType, SymbolEqualityComparer.Default)));
195+
existingComponents |= WrapperValueObjectTypeComponents.Constructor.If(type.InstanceConstructors.Any(ctor => ctor is { Parameters.Length: >= 1, DeclaringSyntaxReferences.Length: > 0, }));
198196

199197
existingComponents |= WrapperValueObjectTypeComponents.NullableConstructor.If(underlyingType.IsValueType && type.InstanceConstructors.Any(ctor =>
200198
ctor.Parameters.Length == 1 && ctor.Parameters[0].Type.IsNullableOf(underlyingType)));

DomainModeling.Tests/Comparisons/EnumerableComparerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public sealed partial class StringWrapperValueObject : WrapperValueObject<string
410410
{
411411
protected sealed override StringComparison StringComparison { get; }
412412

413-
public StringWrapperValueObject(string value, StringComparison stringComparison)
413+
public StringWrapperValueObject(string value, StringComparison stringComparison = default)
414414
{
415415
this.Value = value ?? throw new ArgumentNullException(nameof(value));
416416
this.StringComparison = stringComparison.AsDefined();

DomainModeling.Tests/DummyBuilderTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ public TestEntity()
136136
[WrapperValueObject<decimal>]
137137
public sealed partial class Amount
138138
{
139-
// The type's simplest non-default constructor should be used by the builder. It is source-generated.
139+
// The type's simplest non-default constructor should be used by the builder
140+
141+
public Amount(decimal value)
142+
{
143+
this.Value = value;
144+
}
140145

141146
[Obsolete("Just here to confirm that the generated source code is not invoking it.", error: true)]
142147
public Amount(decimal value, string moreComplexConstructor)

DomainModeling.Tests/IdentityTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,11 @@ internal partial struct NestedStringId
943943
[IdentityValueObject<FormatAndParseTestingIntWrapper>]
944944
internal readonly partial struct FormatAndParseTestingIntId
945945
{
946+
public FormatAndParseTestingIntId(FormatAndParseTestingIntWrapper? value)
947+
{
948+
this.Value = value;
949+
}
950+
946951
public FormatAndParseTestingIntId(int value)
947952
{
948953
this.Value = new FormatAndParseTestingIntWrapper(value);
@@ -964,7 +969,7 @@ internal partial struct FormatAndParseTestingUriWrapperId
964969
[IdentityValueObject<JsonTestingIntWrapper>]
965970
internal readonly partial struct JsonTestingIntId
966971
{
967-
public JsonTestingIntId(FormatAndParseTestingIntWrapper _)
972+
public JsonTestingIntId(JsonTestingIntWrapper? _)
968973
{
969974
throw new Exception("This constructor should not be used. This lets tests confirm that concerns such as deserialization correctly avoid constructors.");
970975
}

DomainModeling/DomainModeling.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ Completed support for nested wrappers:
5252
- BREAKING: IIdentityConfigurator/IWrapperValueObjectConfigurator now receive additional method type parameter TCore.
5353

5454
Correct string comparisons with EF via ConfigureIdentityConventions()/ConfigureWrapperValueObjectConventions():
55-
- Feature: These now set a PROVIDER value comparer for each string wrapper property, matching type's case-sensitivity. Since EF Core 7, EF compares keys using provider type instead of model type.
56-
- Feature: These now warn if a string wrapper property has a collation mismatching the type's case-sensitivity (unless collation is explicit).
55+
- Feature: These now set PROVIDER value comparer for each string wrapper property, matching type's case-sensitivity. Since EF Core 7, EF compares keys using provider type, not model type.
56+
- Feature: These now warn if string wrapper property has collation mismatching model's case-sensitivity (unless collation is explicit).
5757
- Feature: These now accept "options" parameter, which allows specifying collations for case-sensitive vs. ignore-case string wrappers.
58-
- Feature: ConfigureDomainModelConventions() now has convenience extension methods CustomizeIdentityConventions()/CustomizeWrapperValueObjectConventions(), for easy custom conventions, such as based on core underlying type.
58+
- Feature: ConfigureDomainModelConventions() now has convenience extensions CustomizeIdentityConventions()/CustomizeWrapperValueObjectConventions(), for easy custom conventions, e.g. based on core underlying type.
5959

6060
Performance:
6161
- Enhancement: Reduced assembly size: generic JSON serializers instead of generated ones.
@@ -67,6 +67,7 @@ Misc:
6767
- Semi-breaking: Entity&lt;TId&gt; now has ID-based ==/!=.
6868
- Semi-breaking: IFormattable &amp; co for string wrappers have stopped treating null strings as "", to better reveal mistakes.
6969
- Semi-breaking: IIdentity implements IWrapperValueObject.
70+
- Semi-breaking: Wrappers/Identities generate no parameterized ctor if ANY parameterized exists.
7071
- Feature: Analyzer and extensions for defined enums.
7172
- Feature: Non-generic Wrapper/Identity interfaces.
7273
- Feature: DummyBuilder records cloned on each step, for reuse.
@@ -75,7 +76,7 @@ Misc:
7576
- Feature: Analyzer warns if field initializers might be skipped.
7677
- Fixed: Source-generated default ctor should not exist in case of primary ctor or lacking base default ctor.
7778
- Fixed: Source-generated records would ignore hand-written ToString()/Equals()/GetHashCode().
78-
- Fixed: Source-generated Wrappers/Identities would not recognize manual member implementations if they were explicit interface implementations.
79+
- Fixed: Source-generated Wrappers/Identities would not recognize manual explicit interface implementations.
7980
- Fixed: DummyBuilder generator would struggle with nested types.
8081
- Fixed: "No source generation on nested type" warning would not show.
8182
- Fixed: Custom attribute inheritance.

0 commit comments

Comments
 (0)