-
Notifications
You must be signed in to change notification settings - Fork 5
WithAssignmentLeftSide Code Mapping Condition
Allows testing conditions against the left side of an assignment. This means that for an expression a.b = c, we could change the *current expression to a.b
.
This mapping operation is useful when trying to extract elements from a assignment expression.
Property | Usage | Description |
---|---|---|
SubConditions | Requires/Content property | Subconditions to test |
For this example we want to convert the Microsoft.Phone.Maps.Controls.MapOverlay.GeoCoordinate
property assignments to invocations to the Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation
attached property setter. In order to do this we need to extract parts of the original assignment and place them in an invocation to the attached property setter call.
-- Windows Phone 8 Silverlight--
void SetElementCoordinate(MapOverlay element)
{
element.GeoCoordinate = coordinate;
}
Here's the definition of the 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.Maps.Controls.MapOverlay">
<map:CodeMapPackage.Maps>
<map:CodeMap Kind="Type">
<map:ReplaceClassUsage NewNamespace="Windows.UI.Xaml.Controls"
NewClassName="ContentControl"/>
</map:CodeMap>
...
<map:CodeMap Kind="Assign" MemberName="GeoCoordinate">
<map:Conditional>
<map:Case>
<map:Case.Condition>
<map:WithAssignment>
<map:WithAssignmentLeftSide>
<map:WithLeftSideOfDottedAccess>
<map:AssignName>$obj</map:AssignName>
</map:WithLeftSideOfDottedAccess>
</map:WithAssignmentLeftSide>
<map:WithAssignmentRightSide>
<map:AssignName>$value</map:AssignName>
</map:WithAssignmentRightSide>
</map:WithAssignment>
</map:Case.Condition>
<map:Case.Action>
<map:ReplaceWithTemplate>
Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation($obj, $value)
</map:ReplaceWithTemplate>
</map:Case.Action>
</map:Case>
...
</map:Conditional>
</map:CodeMap>
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>
After applying this mapping we get the following code:
--Windows UWP--
void SetElementCoordinate(Windows.UI.Xaml.Controls.ContentControl element)
{
Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(element, coordinate);
}
TheWithAssignment
mapping condition is useful when it is necessary to extract parts of an assignment expression. Here's an illustration on how this works:
- This condition succeeds if the current expression is an assignment and its inner conditions succeed
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