-
Notifications
You must be signed in to change notification settings - Fork 5
ReplaceWithTemplate Code Action
ldfallas edited this page Aug 31, 2015
·
3 revisions
Replaces the current expression with the result of evaluating a C# code template.
This mapping action is commonly used in conjunction with the [Conditional Code Action](Conditional Code Action) and the [AssignName Code Mappings condition](AssignName Code Mappings condition).
Property | Usage | Description |
---|---|---|
CodeTemplate | Content property / Required | The C# code template |
Say that we want to replace usages of the System.MessagBox.Show
method to usages of the MessageDialog
class (https://msdn.microsoft.com/library/windows/apps/br208674)
For example we may have the following Windows Phone 8.0 code:
MessageBox.Show("Hi!");
The mapping definition for this scenario looks like this:
<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>
...
<map:Default>
<map:Keep/>
</map:Default>
</map:Conditional>
</map:CodeMap>
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>
The converted code looks like this:
await (new Windows.UI.Popups.MessageDialog("Hi!")).ShowAsync()
- The template specified for this code mapping action must be a valid C# expression. If not the mapping action will not be applied.
- Variables are specified using the dollar sign ($) followed by a sequence of letters
- Since C# code may contain angle brackets it is recommented to specify the code template in a CDATA block (https://en.wikipedia.org/wiki/CDATA) .
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