Skip to content

Commit

Permalink
Adding sealed/readonly on class/struct is not necessary anymore, sour…
Browse files Browse the repository at this point in the history
…ce gen takes this over
  • Loading branch information
PawelGerr committed Aug 20, 2024
1 parent d3e31fa commit 023667e
Show file tree
Hide file tree
Showing 135 changed files with 810 additions and 898 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[ComplexValueObject]
public sealed partial class BoundaryWithJsonConverter
public partial class BoundaryWithJsonConverter
{
public decimal Lower { get; }
public decimal Upper { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[SmartEnum<string>(IsValidatable = true)]
public sealed partial class ProductCategoryWithJsonConverter
public partial class ProductCategoryWithJsonConverter
{
public static readonly ProductCategoryWithJsonConverter Fruits = new("Fruits");
public static readonly ProductCategoryWithJsonConverter Dairy = new("Dairy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture;

[SmartEnum<int>(IsValidatable = true)]
public sealed partial class ProductGroupWithJsonConverter
public partial class ProductGroupWithJsonConverter
{
public static readonly ProductGroupWithJsonConverter Apple = new(1, "Apple", ProductCategory.Fruits);
public static readonly ProductGroupWithJsonConverter Orange = new(2, "Orange", ProductCategory.Fruits);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[SmartEnum<string>]
public sealed partial class ProductTypeWithJsonConverter
public partial class ProductTypeWithJsonConverter
{
public static readonly ProductTypeWithJsonConverter Groceries = new("Groceries");
public static readonly ProductTypeWithJsonConverter Housewares = new("Housewares");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[ComplexValueObject]
public sealed partial class BoundaryWithJsonConverter
public partial class BoundaryWithJsonConverter
{
public decimal Lower { get; }
public decimal Upper { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[SmartEnum<string>(IsValidatable = true)]
public sealed partial class ProductCategoryWithJsonConverter
public partial class ProductCategoryWithJsonConverter
{
public static readonly ProductCategoryWithJsonConverter Fruits = new("Fruits");
public static readonly ProductCategoryWithJsonConverter Dairy = new("Dairy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture;

[SmartEnum<int>(IsValidatable = true)]
public sealed partial class ProductGroupWithJsonConverter
public partial class ProductGroupWithJsonConverter
{
public static readonly ProductGroupWithJsonConverter Apple = new(1, "Apple", ProductCategory.Fruits);
public static readonly ProductGroupWithJsonConverter Orange = new(2, "Orange", ProductCategory.Fruits);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[SmartEnum<string>]
public sealed partial class ProductTypeWithJsonConverter
public partial class ProductTypeWithJsonConverter
{
public static readonly ProductTypeWithJsonConverter Groceries = new("Groceries");
public static readonly ProductTypeWithJsonConverter Housewares = new("Housewares");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.Database;

[ValueObject<string>]
public sealed partial class Description
public partial class Description
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.Database;

[ValueObject<string>]
public readonly partial struct DescriptionStruct
public partial struct DescriptionStruct
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.Database;

[ValueObject<string>]
public sealed partial class Name
public partial class Name
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.Database;

[ValueObject<string>]
public readonly partial struct NameStruct
public partial struct NameStruct
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Thinktecture.Database;

// ReSharper disable InconsistentNaming
[SmartEnum<int>]
public sealed partial class TestSmartEnum_Class_IntBased
public partial class TestSmartEnum_Class_IntBased
{
public static readonly TestSmartEnum_Class_IntBased Value1 = new(0);
public static readonly TestSmartEnum_Class_IntBased Value2 = new(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Thinktecture.Database;

// ReSharper disable InconsistentNaming
[SmartEnum<string>]
public sealed partial class TestSmartEnum_Class_StringBased
public partial class TestSmartEnum_Class_StringBased
{
public static readonly TestSmartEnum_Class_StringBased Value1 = new("Value1");
public static readonly TestSmartEnum_Class_StringBased Value2 = new("Value2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Thinktecture.Database;

// ReSharper disable InconsistentNaming
[SmartEnum<int>(IsValidatable = true)]
public readonly partial struct TestSmartEnum_Struct_IntBased
public partial struct TestSmartEnum_Struct_IntBased
{
public static readonly TestSmartEnum_Struct_IntBased Value1 = new(0);
public static readonly TestSmartEnum_Struct_IntBased Value2 = new(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Thinktecture.Database;

// ReSharper disable InconsistentNaming
[SmartEnum<string>(IsValidatable = true)]
public readonly partial struct TestSmartEnum_Struct_StringBased
public partial struct TestSmartEnum_Struct_StringBased
{
public static readonly TestSmartEnum_Struct_StringBased Value1 = new("Value1");
public static readonly TestSmartEnum_Struct_StringBased Value2 = new("Value2");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[ComplexValueObject]
public sealed partial class BoundaryWithMessagePackFormatter
public partial class BoundaryWithMessagePackFormatter
{
public decimal Lower { get; }
public decimal Upper { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture;

[ValueObject<string>(NullInFactoryMethodsYieldsNull = true)]
public sealed partial class ProductNameWithMessagePackFormatter
public partial class ProductNameWithMessagePackFormatter
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture;

[SmartEnum<string>]
public sealed partial class ProductTypeWithMessagePackFormatter
public partial class ProductTypeWithMessagePackFormatter
{
public static readonly ProductTypeWithMessagePackFormatter Groceries = new("Groceries");
public static readonly ProductTypeWithMessagePackFormatter Housewares = new("Housewares");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture.SmartEnums;

[SmartEnum<string>]
public sealed partial class EnumWithBaseClass : SomeBaseClass
public partial class EnumWithBaseClass : SomeBaseClass
{
public static readonly EnumWithBaseClass Item1 = new("item 1", 42);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Thinktecture.SmartEnums;

[SmartEnum<string>(IsValidatable = true,
KeyMemberName = "Name")]
public sealed partial class ProductCategory
public partial class ProductCategory
{
public static readonly ProductCategory Fruits = new("Fruits");
public static readonly ProductCategory Dairy = new("Dairy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Thinktecture.SmartEnums;
[SmartEnum<string>]
[ValueObjectKeyMemberComparer<ComparerAccessors.StringOrdinal, string>]
[ValueObjectKeyMemberEqualityComparer<ComparerAccessors.StringOrdinal, string>]
public sealed partial class ProductCategoryWithCaseSensitiveComparer
public partial class ProductCategoryWithCaseSensitiveComparer
{
public static readonly ProductCategoryWithCaseSensitiveComparer FruitsLowerCased = new("fruits");
public static readonly ProductCategoryWithCaseSensitiveComparer FruitsUpperCased = new("FRUITS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Thinktecture.SmartEnums;
[SmartEnum<int>(IsValidatable = true,
ComparisonOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads,
SkipToString = true)]
public sealed partial class ProductGroup
public partial class ProductGroup
{
public static readonly ProductGroup Apple = new(1, "Apple", ProductCategory.Fruits);
public static readonly ProductGroup Orange = new(2, "Orange", ProductCategory.Fruits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Thinktecture.SmartEnums;
ComparisonOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads,
SwitchMethods = SwitchMapMethodsGeneration.DefaultWithPartialOverloads,
MapMethods = SwitchMapMethodsGeneration.DefaultWithPartialOverloads)]
public readonly partial struct ProductGroupStruct
public partial struct ProductGroupStruct
{
public static readonly ProductGroupStruct Apple = new(1);
public static readonly ProductGroupStruct Orange = new(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Thinktecture.SmartEnums;
[SmartEnum<string>(SwitchMethods = SwitchMapMethodsGeneration.DefaultWithPartialOverloads,
MapMethods = SwitchMapMethodsGeneration.DefaultWithPartialOverloads)]
[ValueObjectValidationError<ProductTypeValidationError>]
public sealed partial class ProductType
public partial class ProductType
{
public static readonly ProductType Groceries = new("Groceries");
public static readonly ProductType Housewares = new("Housewares");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Thinktecture.SmartEnums;

[SmartEnum]
public sealed partial class SalesCsvImporterType
public partial class SalesCsvImporterType
{
public static readonly SalesCsvImporterType Daily = new(articleIdIndex: 0, volumeIndex: 2, GetDateTimeForDaily);
public static readonly SalesCsvImporterType Monthly = new(articleIdIndex: 2, volumeIndex: 0, GetDateTimeForMonthly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Thinktecture.ValueObjects;
SubtractionOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads,
MultiplyOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads,
DivisionOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads)]
public readonly partial struct Amount
public partial struct Amount
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref decimal value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Thinktecture.ValueObjects;
SubtractionOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads,
MultiplyOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads,
DivisionOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads)]
public sealed partial class AmountClass
public partial class AmountClass
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref int value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Thinktecture.ValueObjects;

[ComplexValueObject]
[ValueObjectValidationError<BoundaryValidationError>]
public sealed partial class Boundary
public partial class Boundary
{
public decimal Lower { get; }
public decimal Upper { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Thinktecture.ValueObjects;
[ComplexValueObject]
[ValueObjectFactory<string>(UseForSerialization = SerializationFrameworks.All)]
[ValueObjectFactory<ValueTuple<int, int>>]
public sealed partial class BoundaryWithFactories
public partial class BoundaryWithFactories
{
public decimal Lower { get; }
public decimal Upper { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Thinktecture.ValueObjects;

[ComplexValueObject(SkipToString = true)]
public sealed partial class ComplexValueObjectWithCustomEqualityComparison
public partial class ComplexValueObjectWithCustomEqualityComparison
{
[ValueObjectMemberEqualityComparer<ComparerAccessors.StringOrdinal, string>]
public string Identifier { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Thinktecture.ValueObjects;
KeyMemberName = "Date", // Source Generator needs to know the name we've chosen
DefaultInstancePropertyName = "Infinite", // "EndDate.Infinite" represent an open-ended end date
EqualityComparisonOperators = OperatorsGeneration.DefaultWithKeyTypeOverloads)] // for comparison with DateOnly without implicit cast
public readonly partial struct EndDate
public partial struct EndDate
{
private readonly DateOnly? _date;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.ValueObjects;

[ValueObject<string>(EmptyStringInFactoryMethodsYieldsNull = true)]
public sealed partial class OtherProductName
public partial class OtherProductName
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.ValueObjects;

[ValueObject<string>(NullInFactoryMethodsYieldsNull = true)]
public sealed partial class ProductName
public partial class ProductName
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Thinktecture.ValueObjects;

[ValueObject<string>(DefaultInstancePropertyName = "None")]
public readonly partial struct ProductNameStruct
public partial struct ProductNameStruct
{
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace Thinktecture.ValueObjects;
[ValueObject<string>]
[ValueObjectKeyMemberComparer<ComparerAccessors.StringOrdinal, string>]
[ValueObjectKeyMemberEqualityComparer<ComparerAccessors.StringOrdinal, string>]
public sealed partial class ProductNameWithCaseSensitiveComparer
public partial class ProductNameWithCaseSensitiveComparer
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Thinktecture.CodeAnalysis.CodeFixes;
public sealed class ThinktectureRuntimeExtensionsCodeFixProvider : CodeFixProvider
{
private const string _MAKE_PARTIAL = "Make the type partial";
private const string _MAKE_STRUCT_READONLY = "Make the type read-only";
private const string _MAKE_MEMBER_PUBLIC = "Make the member public";
private const string _MAKE_FIELD_READONLY = "Make the field read-only";
private const string _REMOVE_PROPERTY_SETTER = "Remove property setter";
Expand All @@ -21,15 +20,13 @@ public sealed class ThinktectureRuntimeExtensionsCodeFixProvider : CodeFixProvid

/// <inheritdoc />
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(DiagnosticsDescriptors.TypeMustBePartial.Id,
DiagnosticsDescriptors.StructMustBeReadOnly.Id,
DiagnosticsDescriptors.EnumItemMustBePublic.Id,
DiagnosticsDescriptors.FieldMustBeReadOnly.Id,
DiagnosticsDescriptors.PropertyMustBeReadOnly.Id,
DiagnosticsDescriptors.AbstractEnumNeedsCreateInvalidItemImplementation.Id,
DiagnosticsDescriptors.InnerEnumOnFirstLevelMustBePrivate.Id,
DiagnosticsDescriptors.InnerEnumOnNonFirstLevelMustBePublic.Id,
DiagnosticsDescriptors.EnumWithoutDerivedTypesMustBeSealed.Id,
DiagnosticsDescriptors.ValueObjectMustBeSealed.Id,
DiagnosticsDescriptors.InitAccessorMustBePrivate.Id);

/// <inheritdoc />
Expand All @@ -55,10 +52,6 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
context.RegisterCodeFix(CodeAction.Create(_MAKE_PARTIAL, _ => AddTypeModifierAsync(context.Document, root, GetCodeFixesContext().TypeDeclaration, SyntaxKind.PartialKeyword), _MAKE_PARTIAL), diagnostic);
}
else if (diagnostic.Id == DiagnosticsDescriptors.StructMustBeReadOnly.Id)
{
context.RegisterCodeFix(CodeAction.Create(_MAKE_STRUCT_READONLY, _ => AddTypeModifierAsync(context.Document, root, GetCodeFixesContext().TypeDeclaration, SyntaxKind.ReadOnlyKeyword), _MAKE_STRUCT_READONLY), diagnostic);
}
else if (diagnostic.Id == DiagnosticsDescriptors.FieldMustBeReadOnly.Id)
{
context.RegisterCodeFix(CodeAction.Create(_MAKE_FIELD_READONLY, _ => AddTypeModifierAsync(context.Document, root, GetCodeFixesContext().FieldDeclaration, SyntaxKind.ReadOnlyKeyword), _MAKE_FIELD_READONLY), diagnostic);
Expand Down Expand Up @@ -87,7 +80,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
context.RegisterCodeFix(CodeAction.Create(_MAKE_TYPE_PUBLIC, _ => ChangeAccessibilityAsync(context.Document, root, GetCodeFixesContext().TypeDeclaration, SyntaxKind.PublicKeyword), _MAKE_TYPE_PUBLIC), diagnostic);
}
else if (diagnostic.Id == DiagnosticsDescriptors.EnumWithoutDerivedTypesMustBeSealed.Id || diagnostic.Id == DiagnosticsDescriptors.ValueObjectMustBeSealed.Id)
else if (diagnostic.Id == DiagnosticsDescriptors.EnumWithoutDerivedTypesMustBeSealed.Id)
{
context.RegisterCodeFix(CodeAction.Create(_SEAL_CLASS, _ => AddTypeModifierAsync(context.Document, root, GetCodeFixesContext().TypeDeclaration, SyntaxKind.SealedKeyword), _SEAL_CLASS), diagnostic);
}
Expand Down
Loading

0 comments on commit 023667e

Please sign in to comment.