Skip to content

WithLeftSideOfDottedAccess Code Mappings condition

ldfallas edited this page Aug 31, 2015 · 4 revisions

Description

Verifies that the current element is a member access (an expression of the form A.B).

Also it allows to test conditions on the left side of a A.B expression.

Properties

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

Example

For this example we're going to use the WithLeftSideOfDottedAccess condition to capture the left side of uses of the Microsoft.Phone.Shell.IApplicationBar.IsVisibleproperty in order to convert them to an expression using the Windows.UI.Xaml.Controls.CommandBar.Visibility property.

Here's an example of the Microsoft.Phone.Shell.IApplicationBar.IsVisible in on a WP8 C# code.

public bool IsBarVisible(IApplicationBar bar)
{
   return bar.IsVisible;
}

We can write the mapping as follows:

<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.Shell.IApplicationBar">
      <map:CodeMapPackage.Maps>
        ...
        <map:CodeMap Kind="MemberAccess" MemberName="IsVisible">
          <map:Conditional>
            <map:Case>
              <map:Case.Condition>
                <map:WithLeftSideOfDottedAccess>
                  <map:AssignName>$owner</map:AssignName>
                </map:WithLeftSideOfDottedAccess>
              </map:Case.Condition>
              <map:Case.Action>
                <map:ReplaceWithTemplate>($owner.Visibility == Visibility.Visible)  </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>

Once this mapping is applied the code the following code is generated:

public bool IsBarVisible(Windows.UI.Xaml.Controls.CommandBar bar)
{
   return (bar.Visibility == Visibility.Visible);
}

It is important to remark that this action changes the expression being tested for all its child conditions. This means that the map:AssignName specified as the inner condition will act on the left side of the expression. This effect is illustrated here:

WithLeftSideOfDOttedAccess behavior

Notes

  • This code mapping condition will fail if the current element is not a A.B expression or if one of its inner conditions fails.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally