-
Notifications
You must be signed in to change notification settings - Fork 5
RemoveParameter Code Mapping Action
ldfallas edited this page Aug 31, 2015
·
3 revisions
<map:RemoveParameter Position="INDEX-OF-PARAMETER-TO-REMOVE"/>This code mapping action removes a parameter from a event handler method declaration.
| Property | Usage | Description |
|---|---|---|
| Position | Required | The position of the argument to remove |
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 with
CodeMaps of typeEventDecl
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