-
Notifications
You must be signed in to change notification settings - Fork 5
WithMemberInitValue Code Mapping condition
ldfallas edited this page Aug 31, 2015
·
4 revisions
<map:WithMemberInitValue MemberName="membername">
...mapping conditions....
</map:WithMemberInitValue>
Allows testing conditions on constructor member initialization values.
For example give the following object initialization expression:
var x = new MyClass {
MyProperty1 = abc,
MyProperty2 = cde,
};
We can test conditions or extract values from the abc
or cde
expressions.
See the MSDN documentation on C# Object Initializers.
Property | Usage | Description |
---|---|---|
SubConditions | Content property | Conditions to be tested with the left side of a A.B expression |
MemberName | Required | The name of property being initialized |
For example we want to transform the following WP8 expression:
--Windows Phone 8 Silverlight--
void DoCall()
{
new PhoneCallTask()
{
DisplayName = "The display name",
PhoneNumber = GetPhoneNumber()
}.Show();
}
To the following UWP expression :
void DoCall()
{
Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(GetPhoneNumber(), "The display name");
}
To do this conversion 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.PhoneCallTask">
<map:CodeMapPackage.Maps>
<map:CodeMap Kind="Call" MemberName="Show">
<map:Conditional>
<map:Case>
<map:Case.Condition>
<map:WithCalledMemberOwner>
<map:WithConstructorCall>
<map:WithMemberInitValue MemberName="PhoneNumber">
<map:AssignName>$phoneNumber</map:AssignName>
</map:WithMemberInitValue>
<map:WithMemberInitValue MemberName="DisplayName">
<map:AssignName>$displayName</map:AssignName>
</map:WithMemberInitValue>
</map:WithConstructorCall>
</map:WithCalledMemberOwner>
</map:Case.Condition>
<map:Case.Action>
<map:ReplaceWithTemplate>
Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI($phoneNumber, $displayName)
</map:ReplaceWithTemplate>
</map:Case.Action>
</map:Case>
...
</map:Conditional>
</map:CodeMap>
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>
The following picture shows how this mapping condition identify different parts of the source code expression.
- This mapping condition succeeds when the specified property is part of the object initializer and the 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