Skip to content

RedirectProperty Code Mapping Action

ldfallas edited this page Aug 31, 2015 · 3 revisions

Usage

<map:RedirectProperty NewPropertyOwner="NEW-PROPERTY-OWNER" NewProperty="NEW-PROPERTY-NAME"/>

Description

Changes the reference to a property to be a reference to an inner property of the current expression.

This means that reference to A.B will be changed to A.C.B .

Properties

​Property ​Usage ​Description
NewPropertyOwner Required The name of the inner property to reference
NewProperty Required The name of the outer property to reference

Example

We want to convert from System.Device.Location.GeoCoordinate to Windows.Devices.Geolocation.GeoPoint . However when applying this conversion we need to change the way the Latitude property is reference.

We want to convert from this code:

-- Windows Phone 8 Silverlight --

public double RetrieveLatitude(GeoCoordinate c)
{
   return c.Latitude;
}

To the following code:

public double RetrieveLatitude(Windows.Devices.Geolocation.Geopoint c)
{
    return c.Position.Latitude;
}

We change use the RedirectProperty mapping action to perform this change:

<MapUnit xmlns="clr-namespace:Mobilize.Mappers.Extensibility.Core;assembly=Mobilize.ExtensibleMappers"
         xmlns:map="clr-namespace:Mobilize.Mappers.Extensibility.Code;assembly=Mobilize.ExtensibleMappers">
  <MapUnit.Elements>
    <map:CodeMapPackage Type="System.Device.Location.GeoCoordinate">
      <map:CodeMapPackage.Maps>
        <map:CodeMap Kind="Type">
          <map:CodeMap.Action>
            <map:ReplaceClassUsage NewNamespace="Windows.Devices.Geolocation" NewClassName="Geopoint" />
          </map:CodeMap.Action>
        </map:CodeMap>
         ...
        <map:CodeMap Kind="MemberAccess" MemberName="Latitude">
          <map:RedirectProperty NewPropertyOwner="Position" NewProperty="Latitude"/>
        </map:CodeMap>
        <map:CodeMap Kind="MemberAccess" MemberName="Longitude">
          <map:RedirectProperty NewPropertyOwner="Position" NewProperty="Longitude"/>
        </map:CodeMap>
         ...
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

Notes

TODO

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally