Skip to content

IsExpressionOfType Code Mapping Condition

ldfallas edited this page Aug 31, 2015 · 3 revisions

Description

This condition succeeds if the full name of the type of the current expression is the same as the specified in the Type property.

Properties

​Property ​Usage ​Description
Type Required The full name of the type to check

Example

For example we want to convert from System.Windows.Documents.InlineCollection.Add for the case when the argument is a string. In this case we need to create a Windows.UI.Xaml.Documents.Run.

The important thing here is that we need to do this only when the argument is of type System.String . In other cases we will leave it as the original expression.

We can write:

<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.Windows.Documents.InlineCollection">
      <map:CodeMapPackage.Maps>

        <map:CodeMap Kind="Type">
          <map:CodeMap.Action>
            <map:ReplaceClassUsage NewNamespace="Windows.UI.Xaml.Documents"
                                   NewClassName="InlineCollection" />
          </map:CodeMap.Action>
        </map:CodeMap>

        <map:CodeMap Kind="Call" MemberName="Add">
          <map:Conditional>
            <map:Case>
              <map:Case.Condition>
                <map:WithMethodCall>
                  <map:WithCalledMemberOwner>
                    <map:AssignName>$owner</map:AssignName>
                  </map:WithCalledMemberOwner>
                  <map:ArgumentCount>1</map:ArgumentCount>
                  <map:WithArgument Position="0">
                    <map:IsExpressionOfType>System.String</map:IsExpressionOfType>
                    <map:AssignName>$param</map:AssignName>
                  </map:WithArgument>
                </map:WithMethodCall>
              </map:Case.Condition>
              <map:Case.Action>
                <map:ReplaceWithTemplate>
                  $owner.Add(new Windows.UI.Xaml.Documents.Run() { Text = $param })
                </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
            <map:Default>
              <map:Keep/>
            </map:Default>
          </map:Conditional>
        </map:CodeMap>
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally