Skip to content

WithAssignment Code Mapping Condition

ldfallas edited this page Aug 31, 2015 · 4 revisions

Description

Verifies that the current expression is a C# assignment.

This mapping operation is useful to extract parts of an 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 mapping condition fails if the current expression is not an assignment or one of its inner conditions fail.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally