-
Notifications
You must be signed in to change notification settings - Fork 5
AddPreStatementFromTemplate Code Action
ldfallas edited this page Aug 31, 2015
·
3 revisions
This mapping action is used to add a statement before the statement where the current expression is located.
| Property | Usage | Description |
|---|---|---|
| CodeTemplate | Content property / Required | The name of the new method to be called |
Say that we want to convert from Microsoft.Phone.Tasks.SmsComposeTask to Windows.ApplicationModel.Char.ChatMessage. When converting the To property to UWP we need to make sure that the list of Recipients is empty. We wil want todo the following conversion:
-- Windows Phone 8 Silverlight--
...
SmsComposeTask tsk = new SmsComposeTask();
...
tsk.To = user;
...We want to convert this code to:
-- Windows UWP --
ChatMessage tsk =...;
...
tsk.Recipients.Clear();
tsk.Recipients.Add(user);To write a conversion for this scenario we can write the following 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.Tasks.SmsComposeTask">
<map:CodeMapPackage.Maps>
<map:CodeMap Kind="Type">
<map:CodeMap.Action>
<map:ReplaceClassUsage
NewNamespace="Windows.ApplicationModel.Chat"
NewClassName="ChatMessage" />
</map:CodeMap.Action>
</map:CodeMap>
<map:CodeMap Kind="Assign" MemberName="To">
<map:Conditional>
<map:Case>
<map:Case.Condition>
<map:WithAssignment>
<map:WithAssignmentLeftSide>
<map:WithLeftSideOfDottedAccess>
<map:AssignName>$owner</map:AssignName>
</map:WithLeftSideOfDottedAccess>
</map:WithAssignmentLeftSide>
<map:WithAssignmentRightSide>
<map:AssignName>$right</map:AssignName>
</map:WithAssignmentRightSide>
</map:WithAssignment>
</map:Case.Condition>
<map:Case.Action>
<map:ActionSequence>
<map:AddPreStatementFromTemplate>
<![CDATA[
$owner.Recipients.Clear();
]]>
</map:AddPreStatementFromTemplate>
<map:ReplaceWithTemplate> $owner.Recipients.Add($right);</map:ReplaceWithTemplate>
</map:ActionSequence>
</map:Case.Action>
</map:Case>
<map:Default>
<map:Keep></map:Keep>
</map:Default>
</map:Conditional>
</map:CodeMap>
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>- A valid C# statement (see https://msdn.microsoft.com/en-us/library/ms173143.aspx) must be specified. If the specified statement is not valid, this action will not be executed
- To avoid problems with angle brackets and other special characters, it is recommended to use a CDATA section (https://en.wikipedia.org/wiki/CDATA) to specify the template.
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