Skip to content

ReplaceParameterDeclarationType Code Action

ldfallas edited this page Aug 31, 2015 · 3 revisions

Usage

<map:ReplaceParameterDeclarationType Position="PARAMETER-POSITION">
    C#-CLASS-NAME
</map:ReplaceParameterDeclarationType>

Description

This code mapping action changes the declaration of the current event handler by replacing the type of the parameter specified by the Position property.

This mapping action can only be used as part of a EventDecl code mapping.

Properties

​Property ​Usage ​Description
Position ​Required A zero-based index indicating the parameter to change the type to
NewTypeName Required​ / Content property The full name of the type to replace current parameter declaration

Examples

We want to write a mapping that converts the event handlers of the System.Windows.Controls.Slider.ValueChanged event to its UWP equivalent.

--Windows Phone 8 Silverlight--

void RegisterHandler()
{
  aSlider.ValueChanged += aSlider_ValueChanged;
}

void aSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
   valueToStore =  e.NewValue;
}

We want to convert this:

-- Windows UWP --

void Moo()
{
    aSlider.ValueChanged += aSlider_ValueChanged;
}

void aSlider_ValueChanged(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)
{
    valueToStore = e.NewValue;
}

In order to change the parameter type of the event handler 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="System.Windows.Controls.Slider">
      <map:CodeMapPackage.Maps>
        ...
        <map:CodeMap Kind="EventDecl" MemberName="ValueChanged">
          <map:CodeMap.Action>
              <map:ReplaceParameterDeclarationType Position="1">
                Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs
              </map:ReplaceParameterDeclarationType>
          </map:CodeMap.Action>
       </map:CodeMap>
       ...
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

Notes

  • This mapping action only a applies to CodeMaps of kind EventDecl.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally