I'm having some trouble with the DAMP PropertyEditorValueConverter. When using your strongly typed example:
var image = new DAMP.PropertyEditorValueConverter.Model(item.GetPropertyValue("logo"))
I'm getting the following error:
Compiler Error Message: CS1502: The best overloaded method match for 'DAMP.PropertyEditorValueConverter.Model.Model(string)' has some invalid arguments
This error is because the item.GetPropertyValue("logo") is already returning a DAMP.PropertyEditorValueConverter.Model instance.
Not what I was expecting, but ok, then I'll just use the following code:
var images = item.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("logo");
This returns a Model, but if "logo" does not exist, it will return null instead of an empty DAMP_List. Because this option will require us to always check for null, this method is not prefered.
Not prefered:
var images = item.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("logo");
if (images != null)
{
foreach (var image in images.Take(1))
{
<img src="@image.TypedCrops["frontpageslideshow"]" alt="@image.Alt" />
}
}
What I would like to do is the following:
var image = item
.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("logo")
.FirstOrDefault();
if (image != null)
{
<img src="@image.TypedCrops["frontpageslideshow"]" alt="@image.Alt" />
}
Or:
var images = item.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("logo");
foreach (var image in images.Take(1))
{
<img src="@image.TypedCrops["frontpageslideshow"]" alt="@image.Alt" />
}
Or:
var images = new DAMP.PropertyEditorValueConverter.Model(item.GetPropertyValue("logo"))
foreach (var image in images.Take(1))
{
<img src="@image.TypedCrops["frontpageslideshow"]" alt="@image.Alt" />
}
Also, the Model() constructor does not check if a Media item actually exists before adding it to the list. If the logo property contains an media ID that does not exist (anymore), it will still add a empty DAMP_Item to the list. This means the Any and Count methods are meaningless, and it will cause errors in the DAMP_Item object when accessing properties on it. So could you check if a media item actually exists before adding a DAMP_Item to the list?
Thanks for the feedback. When I created this the focus was on dynamic and not strongly typed so there probably is room for improvement :-). Will soon release v1.3 and I'll try to fix some of these issues.
DAMP PropertyEditorValueConverter problems
Hey Jeroen,
I'm having some trouble with the DAMP PropertyEditorValueConverter. When using your strongly typed example:
I'm getting the following error:
This error is because the item.GetPropertyValue("logo") is already returning a DAMP.PropertyEditorValueConverter.Model instance.
Not what I was expecting, but ok, then I'll just use the following code:
This returns a Model, but if "logo" does not exist, it will return null instead of an empty DAMP_List. Because this option will require us to always check for null, this method is not prefered.
What I would like to do is the following:
Or:
Or:
Also, the Model() constructor does not check if a Media item actually exists before adding it to the list. If the logo property contains an media ID that does not exist (anymore), it will still add a empty DAMP_Item to the list. This means the Any and Count methods are meaningless, and it will cause errors in the DAMP_Item object when accessing properties on it. So could you check if a media item actually exists before adding a DAMP_Item to the list?
Could you fix some of these issues?
Hello,
Thanks for the feedback. When I created this the focus was on dynamic and not strongly typed so there probably is room for improvement :-). Will soon release v1.3 and I'll try to fix some of these issues.
Jeroen
Looking forward to it :-) Thanks for your quick response.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.