Skip to content

WritingCodeMappings

ldfallas edited this page Sep 11, 2015 · 6 revisions

Mappings are used to specify the way a Windows Phone Silverlight API is converted to a Windows UWP API.

These mappings are specified for each source property, method, event or class to be converted to the target platform.

Code mappings are applied to C# source code. These mappings can be written using XAML files with .MAP extension. See Testing a mapping for more details on how to add a mapping to the conversion tool.

Here's an example of a basic map file.

<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="Windows.Phone.Speech.Recognition.SpeechRecognizerUISettings">
      <map:CodeMapPackage.Maps>
        <map:CodeMap Kind="Type">
          <map:ReplaceClassUsage NewNamespace="Windows.Media.SpeechRecognition"
                                 NewClassName="SpeechRecognizerUIOptions" />
        </map:CodeMap>
        <map:CodeMap Kind="MemberAccess" MemberName="ListenText">
          <map:ReplaceWithProperty NewProperty="AudiblePrompt" />
        </map:CodeMap>
        <map:CodeMap Kind="MemberAccess" MemberName="ReadoutEnabled">
          <map:ReplaceWithProperty NewProperty="IsReagdBackEnabled" />
        </map:CodeMap>
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

MapUnit

A mapping file contains a MapUnit. A map unit can have one or more CodeMapPackage.

CodeMapPackage

A CodeMapPackage specify the operations uses of the members of one class. In the example above the CodeMapPackage is defined for the Windows.Phone.Speech.Recognition.SpeechRecognizerUISettings type . A CodeMapPackage contains a sequence of CodeMap elements.

CodeMap

The CodeMap element specify the way a member of the CodePackage class is converted to the target element. The 'Kind' property of the CodeMap element specify the kind of element this mapping will process. The following list enumerates the kinds of elements that can be processed:

Kind Description More information / Examples
Assign Acts on assignment expressions to the current member (ex. x.Prop = 1) WithAssignment
Call Acts on method call expression for the current member (ex x.Foo() ) WithMethodCall
ElementAccess Acts on indexer access expressions such as (ex. x.Foo["x"]) RedirectIndexer
EventDecl Acts on event handlers for a given event of the current mapping class Writing a mapping for event handlers
InterfaceImplementation Acts on interface implementations of the current type (if it is an interface) Writing a mapping for interface implementations
New Acts on constructor invocations of the current type WithConstructorCall
Type Acts on type usages (variable declarations, fields , parameters, etc.) ReplaceClassUsage

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally