-
Notifications
You must be signed in to change notification settings - Fork 1
Migration from v6 to v7
Pawel Gerr edited this page Nov 28, 2023
·
4 revisions
- Renamed extension method
AddEnumAndValueObjectConverters
toAddValueObjectConverters
- 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
KeyMemberName
instead ofKeyPropertyName
to 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
ValueObjectKeyMemberEqualityComparerAttribute
instead ofstatic IEqualityComparer<string> KeyEqualityComparer
to 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, whereT
is the type of the key member.- Optional: Use
KeyMemberName
,KeyMemberAccessModifier
andKeyMemberKind
to 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
ComplexValueObjectAttribute
for 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
/ValueObjectKeyMemberEqualityComparerAttribute
instead ofValueObjectMemberEqualityComparer
/ValueObjectMemberComparer
to 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
ValidationError
instead 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}'");
}
}