GetPropertyConvert and SetPropertyConvert - how about a NameValueList converter?

GetPropertyConvert and SetPropertyConvert - how about a NameValueList converter?

Old forum URL: forums.lhotka.net/forums/t/8655.aspx


tiago posted on Saturday, March 13, 2010

It looks like GetPropertyConvert and SetPropertyConvert were designed for the string <-> SmartDate conversion only.

I do a lot of conversions string <-> NameValueList like:

public string Status
{
    get
    {
        return StatusNVL.GetNVL().Value(GetProperty(StatusIDProperty));
    }
    set
    {
        SetProperty(StatusIDProperty, StatusNVL.GetNVL().Key(value));
    }
}

and could use a NameValueList converter.

Where do I sign for the wish list?

RockfordLhotka replied on Saturday, March 13, 2010

GetPropertyConvert/SetPropertyConvert work with any convertible values or values that can be cast from one type to another. They use the CoerceValue() helper method, which uses every technique I'm aware of in .NET to try and convert the values from one type to another.

This doesn't include looking up values in lists - that's way beyond type coercion and requires knowledge of the structure of the list and the elements contained in the list.

To do what you are describing I typically have two properties and a business rule or two. When one of the properties is set, the business rule is triggered, and in the rule it locates the value in the lookup list and sets the other property.

So I might have Status and StatusId properties. Set StatusId to a value, and it has a business rule that changes Status (via LoadProperty() to avoid an infinite loop).

Copyright (c) Marimer LLC