-
Notifications
You must be signed in to change notification settings - Fork 5
AssignName Code Mappings condition
This condition is used to assign a name to the current element being tested.
Name are specified using a dollar sign ($) followed by a sequence of letters. For example $expr
.
Assigning a name inside a condition is useful when parts of an input expression need to be reused in a target expression. This condition is useful when used in conjunction with the [ReplaceWithTemplate Code Action](ReplaceWithTemplate Code Action) or the [AddPreStatementFromTemplate Code Action](AddPreStatementFromTemplate Code Action) .
This condition always succeeds if the name of the variable is valid.
Property | Usage | Description |
---|---|---|
Name | Content property /Required | The name of the variable that refers to the current expression. |
Say that we want to convert the Microsoft.Phone.Controls.WebBrowser.InvokeScript method to the WebView.InvokeScriptAsync method. In order to do this we need to take parts of the original expression and assign names to it.
Here's an implementation of this 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="Microsoft.Phone.Controls.WebBrowser">
<map:CodeMapPackage.Maps>
<map:CodeMap Kind="Type">
<map:CodeMap.Action>
<map:ReplaceClassUsage NewNamespace="Windows.UI.Xaml.Controls"
NewClassName="WebView" />
</map:CodeMap.Action>
</map:CodeMap>
...
<map:CodeMap Kind="Call" MemberName="InvokeScript">
<map:Conditional>
<map:Case>
<map:Case.Condition>
<map:WithMethodCall>
<map:WithCalledMemberOwner>
<map:AssignName>$webView</map:AssignName>
</map:WithCalledMemberOwner>
<map:WithArgument Position="0">
<map:AssignName>$function</map:AssignName>
</map:WithArgument>
<map:AssignNameToArgumentRange From="1" Name="$argsFromtwo"/>
</map:WithMethodCall>
</map:Case.Condition>
<map:Case.Action>
<map:ReplaceWithTemplate>
await $webView.InvokeScriptAsync($function, new[] {$argsFromtwo})
</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>
The condition of this mapping expression extracts parts of the original expression. The following picture shows how the different parts of the expression are captured:
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