-
Notifications
You must be signed in to change notification settings - Fork 5
WithLambdaExpressionBody Mappings condition
ldfallas edited this page Aug 31, 2015
·
3 revisions
<map:WithLambdaExpressionBody>
... conditions ...
</map:WithLambdaExpressionBody>
Tests conditions against the lambda expression body.
Property | Usage | Description |
---|---|---|
Subconditions | Content property | Conditions to test against the lambda parameter |
Say that we want to convert uses of System.Collections.Generic.List<T>.ForEach
to a foreach
statement.
For example we want to turn:
public void DoTask(List<int> aList)
{
aList.ForEach(x => System.Diagnostics.Debug.WriteLine(x));
}
Into the following expression:
public void DoTask(List<int> aList)
{
foreach ( var x in aList )
{
System.Diagnostics.Debug.WriteLine(x);
}
}
Here we use the WithMethodCall
element to identify the method call and perform more inner checks.
<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.Collections.Generic.List">
<map:CodeMapPackage.Maps>
<map:CodeMap Kind="Call" MemberName="ForEach">
<map:Conditional>
<map:Case>
<map:Case.Condition>
<map:WithMethodCall>
<map:ArgumentCount>1</map:ArgumentCount>
<map:WithCalledMemberOwner>
<map:AssignName>$obj</map:AssignName>
</map:WithCalledMemberOwner>
<map:WithArgument Position="0">
<map:WithLambdaExpressionParameter Index="0">
<map:AssignName>$x</map:AssignName>
</map:WithLambdaExpressionParameter>
<map:WithLambdaExpressionBody>
<map:AssignName>$body</map:AssignName>
</map:WithLambdaExpressionBody>
</map:WithArgument>
</map:WithMethodCall>
</map:Case.Condition>
<map:Case.Action>
<map:ActionSequence>
<map:AddPreStatementFromTemplate>
foreach(var $x in $obj) {
$body;
}
</map:AddPreStatementFromTemplate>
<map:RemoveCurrentStatement />
</map:ActionSequence>
</map:Case.Action>
</map:Case>
<map:Default>
<map:Keep />
</map:Default>
</map:Conditional>
</map:CodeMap>
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>
- This mapping condition fails if the current element is not a lambda expression
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