Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I use Switcher all the time, but I find it weird that ModelsBuilder doesn't know that it's "just" an int (it registers as object - not even a bool).
I usually do this to get the value:
bool isSuperAwesome = Model.GetPropertyValue<int>("Awesome") == 1;
but I would love to know if it's possible to throw a custom PropertyEditorValueConvert (or whatever it's called) after it - and how I might do that without compiling DLLs etc. :)
I have the code below, You can just added it your own solution. You can add it into App_Code folder if want but its not recommended :)
public class SwitcherPropertyConverter : PropertyValueConverterBase
public override bool IsConverter(PublishedPropertyType propertyType)
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
if (source == null) return false;
bool value = false;
if (source is int)
value = (int)source == 1;
Thanks Matt - that one goes straight into my folder of good stuff :-)
Yes, ModelsBuilder return an object by default unless there exists a property value converter to handle the return type, where the strongly typed syntax (and ModelsBuilder) know the return type.
I could add a property value converter for this in the package as requested here https://github.com/bjarnef/Switcher/issues/6 but I find it a bit overkill the add another assembly just to handle this and when Umbraco core already have property value converters for this.
I have created a issue here that it should be possible to re-use property value converters for simple types https://github.com/umbraco/Umbraco-CMS/issues/4419 (the original issue was created here https://issues.umbraco.org/issue/U4-10005)
Awesome - thanks for the explanation Bjarne!
(I did think we'd discussed this earlier at a meetup :)
Totally agree on the overkill part, too.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted