Skip to content

ArgumentCount Code Mappings condition

ldfallas edited this page Aug 31, 2015 · 3 revisions

Description

Checks the number of arguments of a method call.

This condition is used to constrain the number of arguments of a method call in a [Conditional Code Action mapping action](Conditional Code Action mapping action ) Case.

Properties

Property ​Usage ​Description
Count Content property/​Required The number of arguments of the current method call

Example

Say that we are creating a mapping for MessageBox.Show. This method has several overloads. In this case we want to create a mapping that does something for the case when the method is called with one argument, and do something else when the method is called with three arguments.

Here's 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="System.Windows.MessageBox">
      <map:CodeMapPackage.Maps>
        <map:CodeMap Kind="Call" MemberName="Show">
          <map:Conditional>
            <!-- Case for one argument -->
            <map:Case>
              <map:Case.Condition>
                <map:WithMethodCall>
                  <map:ArgumentCount>1</map:ArgumentCount>
                  <map:WithArgument Position="0">
                    <map:AssignName>$message</map:AssignName>
                  </map:WithArgument>
                </map:WithMethodCall>
              </map:Case.Condition>
              <map:Case.Action>
                <map:ReplaceWithTemplate>
                  await (new Windows.UI.Popups.MessageDialog($message)).ShowAsync()
                </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
            <!-- Case for three arguments with OK -->
            <map:Case>
              <map:Case.Condition>
                <map:WithMethodCall>
                  <map:ArgumentCount>3</map:ArgumentCount>
                  <map:WithArgument Position="0">
                    <map:AssignName>$message</map:AssignName>
                  </map:WithArgument>
                  <map:WithArgument Position="1">
                    <map:AssignName>$title</map:AssignName>
                  </map:WithArgument>
                  <map:WithArgument Position="2">
                    <map:Equals>MessageBoxButton.OK</map:Equals>
                  </map:WithArgument>
                </map:WithMethodCall>
              </map:Case.Condition>
              <map:Case.Action>
                <map:ReplaceWithTemplate>
                  await (new Windows.UI.Popups.MessageDialog($message, $title)).ShowAsync()
                </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
            ...
          </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