-
Notifications
You must be signed in to change notification settings - Fork 5
Writing a simple namespace mapping
Some Windows Phone Silverlight APIs have the same class names as their equivalents in UWP . A common difference is the namespace .
For example the following code:
-- Windows Phone Silverlight --
System.Windows.Controls.Button myButton;
myButton = new System.Windows.Controls.Button();This code must be changed to the following UWP equivalent:
-- Windows UWP --
Windows.UI.Xaml.Controls.Button myButton;
myButton = new Windows.UI.Xaml.Controls.Button();In this case we need to create a 'Type' mapping that allows us to convert type references from System.Windows.Controls.Button to Windows.UI.Xaml.Controls.Button. The following code shows the definition of a MapUnit for the System.Windows.Controls.Button class.
** -- Converter mapping -- ***
<MapUnit xmlns="clr-namespace:Mobilize.Mappers.Extensibility.Core;assembly=Mobilize.ExtensibleMappers"
xmlns:map="clr-namespace:Mobilize.Mappers.Extensibility.Code;assembly=Mobilize.ExtensibleMappers">
<map:CodeMapPackage Type="System.Windows.Controls.Button">
<map:CodeMap Kind="Type">
<map:ReplaceClassUsage NewNamespace="Windows.UI.Xaml.Controls"
NewClassName="Button" />
</map:CodeMap>
</map:CodeMapPackage>
</MapUnit>You can register this mapping by following the instructions in the [Registering new code mappings](Registering new code mappings) .
When a namespace has completely disappeared , for example the System.Windows.Controls namespace doesn't exist anymore then we need to remove or replace the namespace import declarations at the top of source code files.
For example:
-- Windows Phone Silverlight --
using System.Windows.Controls;
public class MyClass
{
...
}This code could be converted to:
-- Windows UWP --
using Windows.Xaml.UI;
public class MyClass
{
...
}Conversion for using declarations
-- Converter namespace mapping --
<NamespaceMappings xmlns="clr-namespace:Mobilize.Mappers.Extensibility.Namespaces;assembly=Mobilize.ExtensibleMappers">
<Replace Old="System.Windows.Controls" New="Windows.UI.Xaml.Controls"/>
</NamespaceMappings>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