Skip to content

WithMemberInitValue Code Mapping condition

ldfallas edited this page Aug 31, 2015 · 4 revisions

Usage

<map:WithMemberInitValue MemberName="membername">
  ...mapping conditions....
</map:WithMemberInitValue>

Description

Allows testing conditions on constructor member initialization values.

For example give the following object initialization expression:

var x  = new MyClass {
   MyProperty1 = abc,
   MyProperty2 = cde,
};

We can test conditions or extract values from the abc or cde expressions.

See the MSDN documentation on C# Object Initializers.

Properties

Property Usage Description
SubConditions Content property Conditions to be tested with the left side of a A.B expression
MemberName Required The name of property being initialized

Example

For example we want to transform the following WP8 expression:

--Windows Phone 8 Silverlight--

void DoCall()
{
   new PhoneCallTask()
   {
      DisplayName = "The display name",
      PhoneNumber = GetPhoneNumber()
   }.Show();
}

To the following UWP expression :

void DoCall()
{
    Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(GetPhoneNumber(), "The display name");
}

To do this conversion we can write the following mapping:

<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="Microsoft.Phone.Tasks.PhoneCallTask">
      <map:CodeMapPackage.Maps>
        <map:CodeMap Kind="Call" MemberName="Show">
          <map:Conditional>
            <map:Case>
              <map:Case.Condition>
                <map:WithCalledMemberOwner>
                  <map:WithConstructorCall>
                    <map:WithMemberInitValue MemberName="PhoneNumber">
                      <map:AssignName>$phoneNumber</map:AssignName>
                    </map:WithMemberInitValue>
                    <map:WithMemberInitValue MemberName="DisplayName">
                      <map:AssignName>$displayName</map:AssignName>
                    </map:WithMemberInitValue>
                  </map:WithConstructorCall>
                </map:WithCalledMemberOwner>
              </map:Case.Condition>
              <map:Case.Action>
                  <map:ReplaceWithTemplate>
                      Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI($phoneNumber, $displayName)
                  </map:ReplaceWithTemplate>
              </map:Case.Action>
            </map:Case>
           ...
          </map:Conditional>
        </map:CodeMap>
      </map:CodeMapPackage.Maps>
    </map:CodeMapPackage>
  </MapUnit.Elements>
</MapUnit>

The following picture shows how this mapping condition identify different parts of the source code expression.

constructor expression analysis

Notes

  • This mapping condition succeeds when the specified property is part of the object initializer and the inner conditions succeed

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally