-
Notifications
You must be signed in to change notification settings - Fork 5
ReplaceParameterValue Code Action
<map:ReplaceParameterValue Position="PARAMETER-TO-REPLACE-POSITION">
C#-CODE-TEMPLATE
</map:ReplaceParameterValue>
Property | Usage | Description |
---|---|---|
Position | Required | A zero-based index of the parameter to replace the value to |
CodeTemplate | Optional / Content property | A code template with the expression to initialize the argument |
Variable name | Description |
---|---|
$parameter0Name | The name of the first parameter of the current event handler |
$parameter1Name | The name of the second parameter of the current event handler |
... | ... |
$parameterNName | The name of the nth parameter of the current event handler |
Replaces the value of the specified parameter by declaring a local variable with the same name of the given parameter.
This mapping operation is useful when a new event handler requires a parameter value that is not available on the target platform.
In the following example we modify an event handler of the Contacts.SearchCompleted event to be complatible with a Task.ContinueWith call.
-- Windows Phone 8 Silverlight --
public void SearchInContacts()
{
var contacts = new Contacts();
contacts.SearchCompleted += contacts_SearchCompleted;
contacts.SearchAsync(searchFilter, filterKind, null);
}
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
foreach(var result in e.Results)
{
System.Diagnostics.Debug.WriteLine(result.DisplayName);
}
}
The code that we want to get is the following:
-- Windows UWP --
public async void SearchInContacts()
{
var contacts = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync();
//contacts.SearchCompleted += contacts_SearchCompleted;
;
(contacts.GetContactReader(
new Windows.ApplicationModel.Contacts.ContactQueryOptions(searchFilter, filterKind))
.ReadBatchAsync())
.AsTask()
.ContinueWith(contacts_SearchCompleted,
System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
}
void contacts_SearchCompleted(System.Threading.Tasks.Task<Windows.ApplicationModel.Contacts.ContactBatch> sender)
{
var e = sender.Result;
foreach ( var result in e.Contacts )
{
System.Diagnostics.Debug.WriteLine(result.DisplayName);
}
}
Here's the mapping to do this change
<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.UserData.Contacts">
<map:CodeMapPackage.Maps>
...
<map:CodeMap Kind="EventDecl" MemberName="SearchCompleted">
<map:ActionSequence>
<map:ReplaceParameterDeclarationType Position="0">
<![CDATA[System.Threading.Tasks.Task<Windows.ApplicationModel.Contacts.ContactBatch>]]>
</map:ReplaceParameterDeclarationType>
<map:ReplaceParameterValue Position="1">
$parameter0Name.Result
</map:ReplaceParameterValue>
<map:RemoveParameter Position="1"/>
</map:ActionSequence>
</map:CodeMap>
...
</map:CodeMapPackage.Maps>
...
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>
Part of the operations we want to perform is to remove the second argument from the current event handler and reuse its variable name (to avoid changes to the event handler body).
- This code mapping action only works when applied to event handlers. That is when used as part of a
CodeMap
EventDecl
mapping.
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