-
Notifications
You must be signed in to change notification settings - Fork 5
AddNamespaceImport Code Mapping Action
Adds a C# using
directive for the given namespace name in the current file.
Property | Usage | Description |
---|---|---|
NamespaceName | Required | The name of the namespace to import |
Say that we created a helper class that exposes an extension method. As part of a mapping we are going to generate references to this extension method. However in order to use the extension method we need to make sure that the current file has a using
directive that imports the namespace where the class that exposes the extension method is defined.
For example, we created the following extension method to emulate the behavior of System.IO.IsolatedStorage.IsolatedStorageSettings.TryGetValue
.
Here's the definition of the extension method:
/// IsolatedStorageExtensionsHelper.cs
namespace WindowsPhoneUWP.UpgradeHelpers
{
static class IsolatedStorageExtensionsHelper
{
public static bool TryGetValue<T>(this Windows.Storage.ApplicationDataContainer settings, string key, out T value)
{
object tmp;
bool result;
value = default(T);
if (result = settings.TryGetValue(key, out tmp))
{
value = (T)tmp;
}
return result;
}
}
}
The mapping for the System.IO.IsolatedStorage.IsolatedStorageSettings.TryGetValue
method needs to ensure that the WindowsPhoneUWP.UpgradeHelpers
namespace is imported in the current project. To do that we write the following mapping:
<?xml version="1.0" encoding="utf-8"?>
<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.IO.IsolatedStorage.IsolatedStorageSettings">
<map:CodeMapPackage.Maps>
<map:CodeMap Kind="Call" MemberName="TryGetValue">
<map:ActionSequence>
<map:AddHelper Path="..\Helpers\IsolatedStorageExtensionsHelper.cs"/>
<map:AddNamespaceImport>WindowsPhoneUWP.UpgradeHelpers</map:AddNamespaceImport>
</map:ActionSequence>
</map:CodeMap>
</map:CodeMapPackage.Maps>
</map:CodeMapPackage>
</MapUnit.Elements>
</MapUnit>
- This mapping action is useful when adding extension method references
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