Skip to content

WithConstructorCall Code Mapping Condition

ldfallas edited this page Aug 31, 2015 · 3 revisions

Usage

<map:WithConstructorCall>
  ...mapping conditions....
</map:WithConstructorCall>

Description

Allows testing conditions on constructor calls.

Properties

Property Usage Description
SubConditions Content property Conditions to be tested with the left side of a A.B expression

Example

For example we want to transform the following WP8 expression:

--Windows Phone 8 Silverlight--

void DoCall()
{
   new PhoneCallTask()
   {
      DisplayName = "The display name",
      PhoneNumber = GetPhoneNumber()
   }.Show();
}

To the following UWP expression :

void DoCall()
{
    Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(GetPhoneNumber(), "The display name");
}

We can use the WithConstructorCall mapping action to identify the constructor call in the left side of the Show method reference.

<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.Tasks.PhoneCallTask">
      <map:CodeMapPackage.Maps>
        <map:CodeMap Kind="Call" MemberName="Show">
          <map:Conditional>
            <map:Case>
              <map:Case.Condition>
                <map:WithCalledMemberOwner>
                  <map:WithConstructorCall>
                    <map:WithMemberInitValue MemberName="PhoneNumber">
                      <map:AssignName>$phoneNumber</map:AssignName>
                    </map:WithMemberInitValue>
                    <map:WithMemberInitValue MemberName="DisplayName">
                      <map:AssignName>$displayName</map:AssignName>
                    </map:WithMemberInitValue>
                  </map:WithConstructorCall>
                </map:WithCalledMemberOwner>
              </map:Case.Condition>
              <map:Case.Action>
                  <map:ReplaceWithTemplate>
                      Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI($phoneNumber, $displayName)
                  </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
           ...
          </map:Conditional>
        </map:CodeMap>
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

Using the WithConstructorCall condition is going to filter out all expressions that doesn't have a constructor call on the left side of the Show reference.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally