ArgumentCount Code Mappings condition
ldfallas edited this page Aug 31, 2015
·
3 revisions
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.
Property | Usage | Description |
---|---|---|
Count | Content property/Required | The number of arguments of the current method call |
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>
Contact us for more information
Overview
Writing mappings
Code Mapping Actions
- ActionSequence
- AddHelper
- AddNamespaceImport
- AddPreStatementFromTemplate
- CommentOut
- Conditional
- Keep Code Mapping Action
- MarkAsNotMapped
- RedirectCall
- RedirectCallToInnerMember
- RedirectIndexer
- RedirectProperty
- RemoveCurrentStatement
- RemoveParameter
- ReplaceClassUsage
- ReplaceMethodBodyWithTemplate
- ReplaceParameterDeclarationType
- ReplaceParameterMember
- ReplaceParameterValue
- ReplaceWithMethodCall
- ReplaceWithProperty
- ReplaceWithTemplate
Code Mapping Conditions
- AllConditionsApply
- ArgumentCount
- AssignName
- AssignNameToArgumentRange
- IsExpressionOfType
- IsStringLiteralMatchingRegex
- WithArgument
- WithAssignment
- WithAssignmentLeftSide
- WithAssignmentRightSide
- WithCalledMemberOwner
- WithCalledMethodExpression
- WithConstructorCall
- WithLambdaExpressionBody
- WithLambdaExpressionParameter
- WithLeftSideOfDottedAccess
- WithMemberInitValue
- WithMethodCall
XAML mapping actions
- ActionSequence
- AddStatementToConstructorFromTemplate
- BindPropertyValueElement Xaml mapping action
- ChangeEventHandlerEventArgsType
- CommentOutElement
- CommentOutProperty
- MarkAsNotMapped
- MoveValueToContentProperty
- RemoveNamespaceDeclaration
- RenameElement
- RenameProperty
- ReplaceAttributeValue
- ReplaceEventHandlerBodyWithTemplate
- ReplaceEventHandlerParameterMember
- ReplaceNamespaceDeclaration
- ReplacePropertyValueWithParentResource
- ReplaceStaticResourceWithThemeResource
- SetPropertyValueToComplexElement
- SetPropertyValueToSimpleValue
- WrapContent
XAML mapping conditions
Misc