Skip to content

AddHelper Code Action

ldfallas edited this page Aug 17, 2015 · 2 revisions

Description

Adds a file to the target project. This file may contain the implementation of a functionality that is missing in the target platform.

Properties

Property Usage ​Description
​Path ​Required / Content property The path to the helper file to be included

Example

Since the Microsoft.Phone.Tasks.WebBrowserTask class is not available in UWP. We are going to create a small helper class which contains the same functionality exposing the same API.

--Windows Phone 8 Silverlight--

...
var task = new WebBrowserTask();
task.Uri = new Uri("http://localhost/");
task.Show();
...

We are going to define a helper class as followings:

-- Conversion tool helper --

/// WebBrowserTaskHelper.cs
namespace WindowsPhoneUWP.UpgradeHelpers {
    class WebBrowserTaskHelper
    {
        public Uri Uri { get; internal set; }

        internal WebBrowserTaskHelper()
        {
        }

        internal void Show()
        {
             Windows.System.Launcher.LaunchUriAsync(Uri);
        }
    }
}

Now to create a mapping that will include this helper class we can write the following:

    <map:CodeMapPackage Type="Microsoft.Phone.Tasks.WebBrowserTask">
      <map:ActionSequence>
        <map:AddHelper Path="..\Helpers\WebBrowserTaskHelper.cs" />
        <map:ReplaceClassUsage NewNamespace="WindowsPhoneUWP.UpgradeHelpers" NewClassName="WebBrowserTaskHelper" />
      </map:ActionSequence>
    </map:CodeMap>

By executing this mapping we get the following code:

var task = new WindowsPhoneUWP.UpgradeHelpers.WebBrowserTaskHelper();
task.Uri = new Uri("http://localhost/");
task.Show();

Notes

  • The path of the helper file is relative to the root of the mappings folder.
  • The file in the target project is generated in a directory called Helper

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally