-
Notifications
You must be signed in to change notification settings - Fork 5
ReplaceMethodBodyWithTemplate Code Action
ldfallas edited this page Aug 31, 2015
·
3 revisions
Replaces the body of a method declaration where this action is applied.
This action is commonly used when creating a mapping for an event handler. See [Writing a mapping for event handlers](Writing a mapping for event handlers).
| Property | Usage | Description |
|---|---|---|
| CodeTemplate | Content property / Required | The C# code template. This template must specify a valid code block or statement. |
The following mapping will add an if statement that wraps the method body with a condition regarding its first parameter.
<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.UIElement" Name="System.Windows.UIElement">
<map:CodeMapPackage.Maps>
...
<map:CodeMap Kind="EventDecl" MemberName="Tap">
<map:ActionSequence>
<map:ReplaceParameterDeclarationType Position="1">
<![CDATA[Windows.UI.Xaml.RoutedEventArgs]]>
</map:ReplaceParameterDeclarationType>
<map:ReplaceMethodBodyWithTemplate>
<![CDATA[if ($parameter0Name != null) $body;]]>
</map:ReplaceMethodBodyWithTemplate>
</map:ActionSequence>
</map:CodeMap>
...
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>Say that we have the following code:
public int Subscribe()
{
someText.Tap += someText_Tap;
}
void someText_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Tap!");
}After running the conversion tool with this new mapping we get the following code:
public int Subscribe()
{
someText.Tapped += someText_Tap;
}
void someText_Tap(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if ( sender != null )
{
System.Diagnostics.Debug.WriteLine("Tap!");
}
}| Variable name | Description |
|---|---|
| $parameter0Name, $parameter1Name, ..., $parameterXName | The names of the parameters of the current method. Parameter names are 0 based. |
| $body | The block with the body of the current method |
TODO
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