We often need to refactor existing pages and blocks due to new requirements. Usually one or more properties are to be replaced by one or more new properties. Existing pages and blocks need to keep on working and it is not uncommon that settings made using the old properties need to affect the settings of the new properties. Creating new pages or blocks to replace existing ones is not an option - unless it can be automated.
Simple example #1: The old Boolean property UseDarkBackgroundColor is replaced by the new string property BackgroundColor. If UseDarkBackgroundColor was set, BackgroundColor should be set to a specific color.
Simple example #2: The old Boolean property IsWide is replaced by the new property IsNarrow (basically flipping name and value). If IsWide was true, IsNarrow should be false and vice versa.
In the past we have solved this by updating the Episerver database using an SQL script. I find this kind of scary and I would therefore like to find a better approach.
The following article gives me some hope: https://world.episerver.com/documentation/developer-guides/CMS/Content/Refactoring-content-type-classes#API
The information under the section "Renaming a content type by API" is easy to understand and when testing it the result was as expected. However, the text under the section "Changing the type for a property" is next to gibberish to me. I don't even know where to start, even after a lot of googling.
Does anybody know of an example that shows how to change the type (and value) of a property in Episerver without an SQL script?
question from:
https://stackoverflow.com/questions/65902540/change-name-type-and-value-of-a-page-or-block-property-in-episerver 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…