-
Notifications
You must be signed in to change notification settings - Fork 3
Migration from v6 to v7
Pawel Gerr edited this page Nov 28, 2023
·
4 revisions
- Renamed extension method
AddEnumAndValueObjectConverterstoAddValueObjectConverters
- Use
SmartEnumAttribute<T>instead ofEnumGenerationAttribute - Use
SmartEnumAttribute<T>instead ofIEnum<T>
// OLD
[EnumGeneration(KeyPropertyName = "Name")]
public sealed partial class ProductCategory : IEnum<string>
{
public static readonly ProductCategory Fruits = new("Fruits");
public static readonly ProductCategory Dairy = new("Dairy");
}
// NEW
[SmartEnum<string>(KeyPropertyName = "Name")]
public sealed partial class ProductCategory
{
public static readonly ProductCategory Fruits = new("Fruits");
public static readonly ProductCategory Dairy = new("Dairy");
}- Use
SmartEnumAttribute<T>(IsValidatable = true)instead ofIValidatableEnum<T>
// OLD
public sealed partial class ProductCategory : IValidatableEnum<string>
{
public static readonly ProductCategory Fruits = new("Fruits");
public static readonly ProductCategory Dairy = new("Dairy");
}
// NEW
[SmartEnum<string>(IsValidatable = true)]
public sealed partial class ProductCategory
{
public static readonly ProductCategory Fruits = new("Fruits");
public static readonly ProductCategory Dairy = new("Dairy");
}- Use
KeyMemberNameinstead ofKeyPropertyNameto change the name of the key member.
// OLD
[SmartEnum<string>(KeyPropertyName = "Name")]
public sealed partial class ProductCategory
{
}
// NEW
[SmartEnum<string>(KeyMemberName = "Name")]
public sealed partial class ProductCategory
{
}- Use
ValueObjectKeyMemberEqualityComparerAttributeinstead ofstatic IEqualityComparer<string> KeyEqualityComparerto change the equality comparer.
// OLD
[SmartEnum<string>]
public sealed partial class ProductCategoryWithCaseSensitiveComparer
{
public static IEqualityComparer<string> KeyEqualityComparer => StringComparer.Ordinal;
}
// NEW
[SmartEnum<string>]
[ValueObjectKeyMemberEqualityComparer<ComparerAccessors.StringOrdinal, string>]
public sealed partial class ProductCategoryWithCaseSensitiveComparer
{
}- Use
ValueObjectAttribute<T>for simple value objects and remove the key member, whereTis the type of the key member.- Optional: Use
KeyMemberName,KeyMemberAccessModifierandKeyMemberKindto change the generation of the key member.
- Optional: Use
// OLD
[ValueObject]
public sealed partial class ProductName
{
private string Value { get; }
}
[ValueObject<string>]
public sealed partial class ProductName
{
}- Use
ComplexValueObjectAttributefor complex value object
// OLD
[ValueObject]
public sealed partial class Boundary
{
public decimal Lower { get; }
public decimal Upper { get; }
}
// NEW
[ComplexValueObject]
public sealed partial class Boundary
{
public decimal Lower { get; }
public decimal Upper { get; }
} - Use
ValueObjectKeyMemberComparerAttribute/ValueObjectKeyMemberEqualityComparerAttributeinstead ofValueObjectMemberEqualityComparer/ValueObjectMemberComparerto change the equality comparer and comparer.
// OLD
[ValueObject]
public sealed partial class ProductName
{
[ValueObjectMemberEqualityComparer<ComparerAccessors.StringOrdinalIgnoreCase, string>]
[ValueObjectMemberComparer<ComparerAccessors.StringOrdinalIgnoreCase, string>]
private string Value { get; }
}
// NEW
[ValueObject<string>]
[ValueObjectKeyMemberComparer<ComparerAccessors.StringOrdinal, string>]
[ValueObjectKeyMemberEqualityComparer<ComparerAccessors.StringOrdinal, string>]
public sealed partial class ProductName
{
}- Use
ValidationErrorinstead ofValidationResult- Alternatively, implement your own class to be used for validations (see custom type for validation errors for more information)
// OLD
[ValueObject]
public sealed partial class Boundary
{
public decimal Lower { get; }
public decimal Upper { get; }
static partial void ValidateFactoryArguments(ref ValidationResult? validationResult, ref decimal lower, ref decimal upper)
{
if (lower <= upper)
return;
validationResult = new ValidationResult($"Lower boundary '{lower}' must be less than upper boundary '{upper}'",
new[] { nameof(Lower), nameof(Upper) });
}
}
// NEW
[ComplexValueObject]
public sealed partial class Boundary
{
public decimal Lower { get; }
public decimal Upper { get; }
static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref decimal lower, ref decimal upper)
{
if (lower <= upper)
return;
validationError = new ValidationError($"Lower boundary '{lower}' must be less than upper boundary '{upper}'");
}
}