Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Migration from v6 to v7

Pawel Gerr edited this page Nov 28, 2023 · 4 revisions

General

Entity Framework Core Support

  • Renamed extension method AddEnumAndValueObjectConverters to AddValueObjectConverters

Smart Enums

  • Use SmartEnumAttribute<T> instead of EnumGenerationAttribute
  • Use SmartEnumAttribute<T> instead of IEnum<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 of IValidatableEnum<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 of KeyPropertyName 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 of static 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
{
}

Value Objects

  • Use ValueObjectAttribute<T> for simple value objects and remove the key member, where T is the type of the key member.
    • Optional: Use KeyMemberName, KeyMemberAccessModifier and KeyMemberKind to change the generation of the key member.
// 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 of ValueObjectMemberEqualityComparer/ 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 of ValidationResult
// 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}'"); 
   } 
} 
Clone this wiki locally
Morty Proxy This is a proxified and sanitized view of the page, visit original site.