Skip to content

WithCalledMemberOwner Code Mapping Condition

ldfallas edited this page Aug 31, 2015 · 4 revisions

Description

Tests conditions against the owner of a method being called.

This means that for a method call:

  anInstance.foo();

The inner conditions of this element are tested against the anInstance part of the expression.

Properties

Property Usage Description
SubCondition Required/Content property The conditions to test on the left side of the invoked member owner.

Example

The following example captures the variable holding a reference calls to Microsoft.Phone.Maps.Controls.Map.SetView in order to transform them to calls to MapControl.TrySetView .

<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.Map">
      <map:CodeMapPackage.Maps>

        ...
        <map:CodeMap Kind="Call" MemberName="SetView">
          <map:Conditional>
            <map:Case>
              <map:Case.Condition>
                <map:WithMethodCall>
                  <map:WithCalledMemberOwner>
                    <map:AssignName>$mapInstance</map:AssignName>
                  </map:WithCalledMemberOwner>
                  <map:WithArgument Position="0">
                    <map:AssignName>$arg0</map:AssignName>
                  </map:WithArgument>
                  <map:WithArgument Position="1">
                    <map:AssignName>$arg1</map:AssignName>
                  </map:WithArgument>
                </map:WithMethodCall>
              </map:Case.Condition>
              <map:Case.Action>
                <map:ReplaceWithTemplate>
                  await $mapInstance.TrySetViewAsync($arg0, $arg1)
                </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
            ...
          </map:Conditional>
        </map:CodeMap>
        ...
    </map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>

Given the following code:

--Windows Phone 8 Silverlight--

void SetMapView(Map aMap)
{
    aMap.SetView(coordinate, 0.5);
}

We can apply this mapping and get the following code:

async void SetMapView(Windows.UI.Xaml.Controls.Maps.MapControl aMap)
{
    await aMap.TrySetViewAsync(coordinate, 0.5);
}

The WithCalledMemberOwner code action is used in this case to capture parts of a expression. The following picture shows how the different parts of the expression are captured.

capturing parts of a call

Notes

  • This condition succeeds if the current element is of the form a.foo().

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally