<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by Christian Pisani</title> <link>https://world.optimizely.com/blogs/christian-pisani/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>Job for deleting removed properties</title>            <link>https://world.optimizely.com/blogs/christian-pisani/dates/2021/11/job-for-deleting-removed-properties/</link>            <description>&lt;p&gt;I&#39;ve been annoyed by properties staying on page types after deleting them from code, especially on the .Net 5 version where &quot;From Code&quot; doesn&#39;t seem to work. I couldn&#39;t find a way to do this, so I wrote this quick and dirty job for removing them. I simply load all properties from optimizely, and check if a property with the same name exists on the type, and if not, delete it.&lt;/p&gt;
&lt;p&gt;It has not been tested thoroughly, and I would definitely not use it in a production environment, but it saves me a lot of annoynance when working locallly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This deletes all data related to the property, so use with caution.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public class RemovedDeletedPropertiesJob : ScheduledJobBase
    {
        private readonly IContentTypeRepository _contentTypeRepository;
        private readonly IPropertyDefinitionRepository _propertyDefinitionRepository;

        private int _amountDeleted;
        
        public RemovedDeletedPropertiesJob(IContentTypeRepository contentTypeRepository, 
            IPropertyDefinitionRepository propertyDefinitionRepository)
        {
            _contentTypeRepository = contentTypeRepository;
            _propertyDefinitionRepository = propertyDefinitionRepository;
        }
        
        public override string Execute()
        {
            _amountDeleted = 0;
            
            foreach (var contentType in _contentTypeRepository.List())
            {
                var clone = contentType.CreateWritableClone() as ContentType;
                
                if(clone == null) continue;
                
                foreach (var prop in _propertyDefinitionRepository.List(contentType.ID))
                {
                    try
                    {
                        if (contentType.ModelType.GetProperty(prop.Name) == null)
                        {
                            _propertyDefinitionRepository.Delete(prop);
                            _amountDeleted++;
                        }
                    }
                    catch (Exception e) { }
                }
            }

            return $&quot;Removed {_amountDeleted} properties&quot;;
        }&lt;/code&gt;&lt;/pre&gt;</description>            <guid>https://world.optimizely.com/blogs/christian-pisani/dates/2021/11/job-for-deleting-removed-properties/</guid>            <pubDate>Fri, 05 Nov 2021 07:30:35 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>