Skip to content

WithAssignmentLeftSide Code Mapping Condition

ldfallas edited this page Aug 31, 2015 · 4 revisions

Description

Allows testing conditions against the left side of an assignment. This means that for an expression a.b = c, we could change the *current expression to a.b .

This mapping operation is useful when trying to extract elements from a assignment expression.

Properties

​Property ​Usage ​Description
SubConditions Requires/Content property Subconditions to test

Example

For this example we want to convert the Microsoft.Phone.Maps.Controls.MapOverlay.GeoCoordinate property assignments to invocations to the Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation attached property setter. In order to do this we need to extract parts of the original assignment and place them in an invocation to the attached property setter call.

-- Windows Phone 8 Silverlight--

void SetElementCoordinate(MapOverlay element)
{
   element.GeoCoordinate = coordinate;
}

Here's the definition of the mapping:

<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="Microsoft.Phone.Maps.Controls.MapOverlay">
      <map:CodeMapPackage.Maps>
        <map:CodeMap Kind="Type">
          <map:ReplaceClassUsage NewNamespace="Windows.UI.Xaml.Controls"
                                 NewClassName="ContentControl"/>
        </map:CodeMap>
       ...
        <map:CodeMap Kind="Assign" MemberName="GeoCoordinate">
          <map:Conditional>
            <map:Case>
              <map:Case.Condition>
                <map:WithAssignment>
                  <map:WithAssignmentLeftSide>
                    <map:WithLeftSideOfDottedAccess>
                      <map:AssignName>$obj</map:AssignName>
                    </map:WithLeftSideOfDottedAccess>
                  </map:WithAssignmentLeftSide>
                  <map:WithAssignmentRightSide>
                    <map:AssignName>$value</map:AssignName>
                  </map:WithAssignmentRightSide>
                </map:WithAssignment>
              </map:Case.Condition>
              <map:Case.Action>
                <map:ReplaceWithTemplate>
                  Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation($obj, $value)
                </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
            ...
          </map:Conditional>
        </map:CodeMap>
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

After applying this mapping we get the following code:

--Windows UWP--

void SetElementCoordinate(Windows.UI.Xaml.Controls.ContentControl element)
{
    Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(element, coordinate);
}

TheWithAssignment mapping condition is useful when it is necessary to extract parts of an assignment expression. Here's an illustration on how this works:

Assignment example

Notes

  • This condition succeeds if the current expression is an assignment and its inner conditions succeed

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally