Skip to content

Commit a1b94b1

Browse files
committed
ValueObjectMemberSettings is not required for smart enums
1 parent 1f55dd3 commit a1b94b1

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private static void ValidateValueObject(
181181
TypeMustNotBeGeneric(context, type, locationOfFirstDeclaration, "Value Object");
182182
StructMustBeReadOnly(context, type, locationOfFirstDeclaration);
183183

184-
var assignableMembers = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, false, context.CancellationToken, context.ReportDiagnostic)
184+
var assignableMembers = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, false, true, context.CancellationToken, context.ReportDiagnostic)
185185
.Where(m => !m.IsStatic)
186186
.ToList();
187187

@@ -320,7 +320,7 @@ private static void ValidateEnum(
320320
if (isValidatable)
321321
ValidateCreateInvalidItem(context, enumType, keyType, locationOfFirstDeclaration);
322322

323-
enumType.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, false, context.CancellationToken, context.ReportDiagnostic).Enumerate();
323+
enumType.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, false, false, context.CancellationToken, context.ReportDiagnostic).Enumerate();
324324
var baseClass = enumType.BaseType;
325325

326326
while (!baseClass.IsNullOrObject())

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/InstanceMemberInfo.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,29 @@ private InstanceMemberInfo(
5252
public static InstanceMemberInfo? CreateOrNull(
5353
TypedMemberStateFactory factory,
5454
IFieldSymbol field,
55+
bool populateValueObjectMemberSettings,
5556
bool allowedCaptureSymbols)
5657
{
5758
if (field.Type.Kind == SymbolKind.ErrorType)
5859
return null;
5960

6061
var symbol = allowedCaptureSymbols ? field : null;
61-
var settings = ValueObjectMemberSettings.Create(field, field.Type, allowedCaptureSymbols);
62+
var settings = populateValueObjectMemberSettings ? ValueObjectMemberSettings.Create(field, field.Type, allowedCaptureSymbols) : ValueObjectMemberSettings.None;
6263

6364
return new(factory.Create(field.Type), settings, field.Name, (symbol, null), field.IsStatic);
6465
}
6566

6667
public static InstanceMemberInfo? CreateOrNull(
6768
TypedMemberStateFactory factory,
6869
IPropertySymbol property,
70+
bool populateValueObjectMemberSettings,
6971
bool allowedCaptureSymbols)
7072
{
7173
if (property.Type.Kind == SymbolKind.ErrorType)
7274
return null;
7375

7476
var symbol = allowedCaptureSymbols ? property : null;
75-
var settings = ValueObjectMemberSettings.Create(property, property.Type, allowedCaptureSymbols);
77+
var settings = populateValueObjectMemberSettings ? ValueObjectMemberSettings.Create(property, property.Type, allowedCaptureSymbols) : ValueObjectMemberSettings.None;
7678

7779
return new(factory.Create(property.Type), settings, property.Name, (null, symbol), property.IsStatic);
7880
}

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/EnumSourceGeneratorState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public EnumSourceGeneratorState(
5454
BaseType = type.GetBaseType(factory);
5555
HasKeyComparerImplementation = HasHasKeyComparerImplementation(type);
5656
ItemNames = type.EnumerateEnumItems().Select(i => i.Name).ToList();
57-
AssignableInstanceFieldsAndProperties = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, true, cancellationToken).ToList();
57+
AssignableInstanceFieldsAndProperties = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, true, false, cancellationToken).ToList();
5858
}
5959

6060
private static bool HasHasKeyComparerImplementation(INamedTypeSymbol enumType)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ValueObjectMemberSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Thinktecture.CodeAnalysis.ValueObjects;
44

55
public sealed class ValueObjectMemberSettings : IEquatable<ValueObjectMemberSettings>
66
{
7-
private static readonly ValueObjectMemberSettings _none = new(false);
7+
public static readonly ValueObjectMemberSettings None = new(false);
88
private static readonly ValueObjectMemberSettings _noneForString = new(false, null, Constants.ComparerAccessor.ORDINAL_IGNORE_CASE, false, null, Constants.ComparerAccessor.ORDINAL_IGNORE_CASE, false);
99

1010
private readonly SyntaxReference? _equalityComparerAttr;
@@ -47,7 +47,7 @@ public static ValueObjectMemberSettings Create(ISymbol member, ITypeSymbol type,
4747
var comparerAttr = member.FindAttribute(static type => type.Name == "ValueObjectMemberComparerAttribute" && type.ContainingNamespace is { Name: "Thinktecture", ContainingNamespace.IsGlobalNamespace: true });
4848

4949
if (equalityComparerAttr is null && comparerAttr is null)
50-
return type.SpecialType == SpecialType.System_String ? _noneForString : _none;
50+
return type.SpecialType == SpecialType.System_String ? _noneForString : None;
5151

5252
var equalityComparerGenericTypes = equalityComparerAttr?.GetComparerTypes();
5353
var equalityComparerAccessorType = equalityComparerGenericTypes?.ComparerType?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) ?? (type.SpecialType == SpecialType.System_String ? Constants.ComparerAccessor.ORDINAL_IGNORE_CASE : null);

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ValueObjectSourceGeneratorState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ValueObjectSourceGeneratorState(
4242
TypeFullyQualifiedNullAnnotated = type.IsReferenceType ? TypeFullyQualifiedNullable : TypeFullyQualified;
4343
TypeMinimallyQualified = type.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
4444
IsReferenceType = type.IsReferenceType;
45-
AssignableInstanceFieldsAndProperties = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, true, cancellationToken).ToList();
45+
AssignableInstanceFieldsAndProperties = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(factory, true, true, cancellationToken).ToList();
4646
EqualityMembers = GetEqualityMembers();
4747

4848
var factoryValidationReturnType = type.GetMembers()

src/Thinktecture.Runtime.Extensions.SourceGenerator/Extensions/TypeSymbolExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ public static IEnumerable<InstanceMemberInfo> GetAssignableFieldsAndPropertiesAn
460460
this ITypeSymbol type,
461461
TypedMemberStateFactory factory,
462462
bool instanceMembersOnly,
463+
bool populateValueObjectMemberSettings,
463464
CancellationToken cancellationToken,
464465
Action<Diagnostic>? reportDiagnostic = null)
465466
{
@@ -470,8 +471,8 @@ public static IEnumerable<InstanceMemberInfo> GetAssignableFieldsAndPropertiesAn
470471
{
471472
return tuple switch
472473
{
473-
({ } field, _) => InstanceMemberInfo.CreateOrNull(factory, field, allowedCaptureSymbols),
474-
(_, { } property) => InstanceMemberInfo.CreateOrNull(factory, property, allowedCaptureSymbols),
474+
({ } field, _) => InstanceMemberInfo.CreateOrNull(factory, field, populateValueObjectMemberSettings, allowedCaptureSymbols),
475+
(_, { } property) => InstanceMemberInfo.CreateOrNull(factory, property, populateValueObjectMemberSettings, allowedCaptureSymbols),
475476
_ => throw new Exception("Either field or property must be set.")
476477
};
477478
})

0 commit comments

Comments
 (0)