November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
I haven't seen anyone bypassing setters as you described.
Some common scenarios:
Executed once, when a page is created
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
this[MetaDataProperties.PageChildOrderRule] = FilterSortOrder.Alphabetical;
}
Doesn't work in All Properties view
public virtual string MyProperty
{
get { return this.GetPropertyValue(x => x.MyProperty) ?? Name; }
set { this.SetPropertyValue(x => x.MyProperty, value); }
}
Init module
public void Initialize(InitializationEngine context)
{
var events = context.Locate.Advanced.GetInstance<IContentEvents>();
events.SavingContent += Events_SavingContent;
}
private void Events_SavingContent(object sender, EPiServer.ContentEventArgs e)
{
if (e.Content is MyPage myPage)
{
if (myPage.MyProperty == "Foo")
{
myPage.MyProperty = "Boo";
}
}
}
Did you try the example?
No matter this the reason relates to fact that content let’s say exists at DB level. So, if one delete the class, it is still possible to work with created content of that type (in CMS edit) including value sets.
If the model class exists, non-auto property getters are called – at least in some cases – in opposite to setters behaviour.
I struck on that the block property setter is called only once during block “life time”. In case from call within
I performed some tests on this:
1. Create new block
The result is expectable:
2. Create new block again
This time the result is also quite expectable:
3. Publish changes to block from test 2
This result is not so expectable:
Tests conclusion:
The Problem
Imagine situation illustrated by code underneath.
Since issue described in tests this code is useless.
Am I wrong in some part? How to work around this in some good-approach manner?