Tags: Egenskaper

Episerver and renaming a custom property

Until CMS-14783 was completed in EPiServer.CMS.Core 11.14.0 a custom property was always identified by its TypeName, i.e. Alloy.Models.Properties.PropertyStringLst for the property definition below.

namespace Alloy.Models.Properties
{
   [EditorHint(Global.SiteUIHints.Strings)]
   [PropertyDefinitionTypePlugIn(
      Description = "A property for list of strings",
      DisplayName = "String List")]
   public class PropertyStringLst : PropertyLongString
   {

   }
}

Say, I wanted to fix the typo in the class name, renaming PropertyStringLst to PropertyStringList, Episerver would not rename the property but simply create another property in addition to the old. If we were to look into the database, we would find two rows in the table [tblPropertyDefinitionType]. One row with TypeName Alloy.Models.Properties.PropertyStringLst, and one with TypeName Alloy.Models.Properties.PropertyStringList.

With the upgrade to EPiServer.CMS.Core 11.14.0 the table tblPropertyDefinitionType got an additional column, GUID. Adding the GUID parameter to the PropertyDefinitionTypePlugIn-attribute like this, renaming the property will be possible.

namespace Alloy.Models.Properties
{
   [EditorHint(Global.SiteUIHints.Strings)]
   [PropertyDefinitionTypePlugIn(
      Description = "A property for list of strings", 
      DisplayName = "String List",
      GUID = "2C522455-17CE-4D51-BA28-F3577D30EA09")]
   public class PropertyStringLst : PropertyLongString
   {

   }
}

Now, I can finally fix the typo. As long as I keep the same GUID, I may change the class name and namespace.

namespace Alloy.Models.Properties
{
   [EditorHint(Global.SiteUIHints.Strings)]
   [PropertyDefinitionTypePlugIn(
      Description = "A property for list of strings", 
      DisplayName = "String List",
      GUID = "2C522455-17CE-4D51-BA28-F3577D30EA09")]
   public class PropertyStringList : PropertyLongString
   {

   }
}

Remember to always add the GUID and deploy your code, before renaming the property. If you add the GUID and change the name at the same time, the property will still be duplicated.

Found this post helpful? Help keep this blog ad-free by buying me a coffee! ☕