File tree Expand file tree Collapse file tree 6 files changed +22
-7
lines changed
src/Equatable.SourceGenerator
Equatable.Generator.Tests Expand file tree Collapse file tree 6 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -89,3 +89,17 @@ public partial class UserImport
8989 public List <DateTimeOffset >? History { get ; set ; }
9090}
9191```
92+
93+ Works for ` record ` types too
94+
95+ ``` c#
96+ [Equatable ]
97+ public partial record StatusRecord (
98+ int Id ,
99+ [property : StringEquality (StringComparison .OrdinalIgnoreCase )] string Name ,
100+ string ? Description ,
101+ int DisplayOrder ,
102+ bool IsActive ,
103+ [property : SequenceEquality ] List <string > Versions
104+ );
105+ ```
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ namespace Equatable.SourceGenerator;
1212[ Generator ]
1313public class EquatableGenerator : IIncrementalGenerator
1414{
15+ private static SymbolDisplayFormat FullyQualifiedNullableFormat = SymbolDisplayFormat . FullyQualifiedFormat . WithMiscellaneousOptions ( SymbolDisplayMiscellaneousOptions . IncludeNullableReferenceTypeModifier ) ;
16+
1517 public void Initialize ( IncrementalGeneratorInitializationContext context )
1618 {
1719 var provider = context . SyntaxProvider . ForAttributeWithMetadataName (
@@ -152,8 +154,7 @@ private static IEnumerable<IPropertySymbol> GetProperties(INamedTypeSymbol targe
152154
153155 private static EquatableProperty CreateProperty ( List < Diagnostic > diagnostics , IPropertySymbol propertySymbol )
154156 {
155- var format = SymbolDisplayFormat . FullyQualifiedFormat . WithMiscellaneousOptions ( SymbolDisplayMiscellaneousOptions . IncludeNullableReferenceTypeModifier ) ;
156- var propertyType = propertySymbol . Type . ToDisplayString ( format ) ;
157+ var propertyType = propertySymbol . Type . ToDisplayString ( FullyQualifiedNullableFormat ) ;
157158 var propertyName = propertySymbol . Name ;
158159
159160 // look for custom equality
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ namespace Equatable.Entities;
77[ Equatable ]
88public sealed partial record StatusRecord (
99 int Id ,
10- string Name ,
10+ [ property : StringEquality ( StringComparison . OrdinalIgnoreCase ) ] string Name ,
1111 string ? Description ,
1212 int DisplayOrder ,
1313 bool IsActive ,
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ namespace Equatable.Entities;
77[ Equatable ]
88public partial record struct StatusRecordStruct (
99 int Id ,
10- string Name ,
10+ [ property : StringEquality ( StringComparison . OrdinalIgnoreCase ) ] string Name ,
1111 string ? Description ,
1212 int DisplayOrder ,
1313 bool IsActive ,
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ namespace Equatable.Entities;
228228[Equatable]
229229public partial record StatusRecordList(
230230 int Id,
231- string Name,
231+ [property: StringEquality(StringComparison.OrdinalIgnoreCase)] string Name,
232232 string? Description,
233233 int DisplayOrder,
234234 bool IsActive,
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ namespace Equatable.Entities
1010 {
1111 return !(other is null)
1212 && global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Id, other.Id)
13- && global::System.Collections.Generic.EqualityComparer<global::System.String>.Default .Equals(Name, other.Name)
13+ && global::System.StringComparer.OrdinalIgnoreCase .Equals(Name, other.Name)
1414 && global::System.Collections.Generic.EqualityComparer<global::System.String?>.Default.Equals(Description, other.Description)
1515 && global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(DisplayOrder, other.DisplayOrder)
1616 && global::System.Collections.Generic.EqualityComparer<global::System.Boolean>.Default.Equals(IsActive, other.IsActive)
@@ -33,7 +33,7 @@ namespace Equatable.Entities
3333 public override int GetHashCode(){
3434 int hashCode = 1051616673;
3535 hashCode = (hashCode * -1521134295) + global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.GetHashCode(Id!);
36- hashCode = (hashCode * -1521134295) + global::System.Collections.Generic.EqualityComparer<global::System.String>.Default .GetHashCode(Name!);
36+ hashCode = (hashCode * -1521134295) + global::System.StringComparer.OrdinalIgnoreCase .GetHashCode(Name!);
3737 hashCode = (hashCode * -1521134295) + global::System.Collections.Generic.EqualityComparer<global::System.String?>.Default.GetHashCode(Description!);
3838 hashCode = (hashCode * -1521134295) + global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.GetHashCode(DisplayOrder!);
3939 hashCode = (hashCode * -1521134295) + global::System.Collections.Generic.EqualityComparer<global::System.Boolean>.Default.GetHashCode(IsActive!);
You can’t perform that action at this time.
0 commit comments