Skip to content

Writing a mapping for interface implementations

ldfallas edited this page Aug 17, 2015 · 2 revisions

There may be the case that an interface that exists in both the source and the target platform has some differences on its members.

For example the System.Windows.Data.IValueConverter (https://msdn.microsoft.com/en-US/library/windows/apps/system.windows.data.ivalueconverter(v=vs.105).aspx) interface has different parameter types for Convert and ConvertBack methods in the UWP interface Windows.UI.Xaml.Data.IValueConverter ( https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.data.ivalueconverter ) .

For example:

object Convert(
	object value,
	Type targetType,
	Object parameter,
	CultureInfo culture
)

Equivalent UWP member:

object Convert(
  object value,
  Type targetType,
  object parameter,
  string language
)

The InterfaceImplementation mapping kind is used to create a mapping for this scenario.

For example:

<map:CodeMapPackage Type="System.Windows.Data.IValueConverter">
  <map:CodeMapPackage.Maps>
    ...
    <map:CodeMap Kind="InterfaceImplementation">
      <map:ActionSequence>
        <map:ApplyToMethodDeclaration MethodName="Convert">
          <map:ReplaceParameterDeclarationType Position="3">System.String</map:ReplaceParameterDeclarationType>
        </map:ApplyToMethodDeclaration>
        <map:ApplyToMethodDeclaration MethodName="ConvertBack">
          <map:ReplaceParameterDeclarationType Position="3">System.String</map:ReplaceParameterDeclarationType>
        </map:ApplyToMethodDeclaration>
      </map:ActionSequence>
    </map:CodeMap>
  </map:CodeMapPackage.Maps>
</map:CodeMapPackage>

This mapping uses the [ApplyToMethodDeclaration Code Action](ApplyToMethodDeclaration Code Action) which applies a mapping action to a method declaration. The mapping action to be applied in this example is the ReplaceParameterDeclarationType Code Action . Also this example uses the [ActionSequence Code Action](ActionSequence Code Action) to change both the Convert and the ConvertBack method declarations.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally