Skip to content

Migration from v7 to v8

Pawel Gerr edited this page Aug 13, 2024 · 2 revisions

Smart Enums

  • Use named parameters in Switch/Map methods
// OLD (Switch)
productType.Switch(ProductType.Groceries, () => logger.Information("Switch with Action: Groceries"), 
                   ProductType.Housewares, () => logger.Information("Switch with Action: Housewares")); 

// NEW (Switch)
productType.Switch(groceries: () => logger.Information("Switch with Action: Groceries"), 
                   housewares: () => logger.Information("Switch with Action: Housewares")); 


// OLD (Map)
var returnValue = productType.Map(ProductType.Groceries, "Map: Groceries", 
                                  ProductType.Housewares, "Map: Housewares");

// NEW (Map)
var returnValue = productType.Map(groceries: "Map: Groceries", 
                                  housewares: "Map: Housewares");
  • Use SwitchMethods/SkipMapMethods to control the generation of the methods Switch/Map
// OLD
[SmartEnum<string>(SkipSwitchMethods = true, 
                   SkipMapMethods = true)] 
public sealed partial class ProductType 
{ 
   ...
}

// NEW
[SmartEnum<string>(SwitchMethods = SwitchMapMethodsGeneration.None,
                   MapMethods = SwitchMapMethodsGeneration.None)] 
public sealed partial class ProductType 
{ 
   ...
}