WFMapToAttributeValueProvider

The WFMapToAttributeValueProvider class allows to map any property from one class to multiple properties on another class.
In the following example, "PropertyOne" is mapped to both "PropertyTwo" and "PropertyThree", so both will be populated with a value from "PropertyOne":
public class MyDTO
{
   [MapTo("PropertyTwo")]
   [MapTo("PropertyThree")]
   public string PropertyOne { get; set; }
}
public class MyObject
{
   public string PropertyTwo { get; set; }
   public string PropertyThree { get; set; }
}

If properties are of different types, the mapping can still succeed as the UpdateModel() method will attempt to cast the first property value into the type of the second. Dot "." notation can also be used to specify child objects and child properties. For example [MapTo("Customer.Address.City")] will map to the Address object on the Customer class and update the "City" property.
Constructors
  • WFMapToAttributeValueProvider(object source)
Initializes a new instance of the WFMapToAttributeValueProvider class and uses the "source" to provide values and the type of object "source" to find [MapTo()] attributes.
  • WFMapToAttributeValueProvider(Type t, object source)
Initializes a new instance of the WFMapToAttributeValueProvider class and uses the "source" to provide values and the type of "t" to find [MapTo()] attributes.
Interface Implementations
  • IWFValueProvider.ContainsKey(string keyName)
Returns a boolean representing if any mapped property matches "keyname".
  • IWFValueProvider.KeyValue(string keyName, object defaultValue)
Checks if the type provided has any [MapTo()] attributes that match "keyName". If the key is found, the value will be returned. Otherwise, "defaultValue" will be returned. The value is not checked for null/empty.
  • IWFValueProvider.KeyValue(string keyName)
Returns the value of a property that maps to "keyName". An exception will be thrown if no property is found to map to "keyName".
  • IWFValueProvider.GetPropertyEnumerator()
Returns the collection mapped property names as an enumerable of String.

Last edited May 21, 2012 at 8:16 PM by aikeru, version 1

Comments

No comments yet.