Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niek 8 posts 28 karma points
    Dec 04, 2012 @ 15:51
    Niek
    0

    DAMP PropertyEditorValueConverter problems

    Hey Jeroen,

    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?

    Could you fix some of these issues?

     

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Dec 04, 2012 @ 15:54
    Jeroen Breuer
    0

    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

  • Niek 8 posts 28 karma points
    Dec 04, 2012 @ 15:59
    Niek
    0

    Looking forward to it :-) Thanks for your quick response.

  • 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.

Please Sign in or register to post replies