Using Custom adapters

You must place the adapters in a mapping file to use the adapters in the binding. You must use the inline adapter binding to link the adapter to entities on the logical and physical sides.

Following code includes examples related to fields, events and commands:

<?xml version="1.0" encoding="utf-8"?>
<PhysicalViewMappings>
  <Adapters>
    <AdapterReference Name="MyAdapterName" Type="FullyQualifiedType" fieldComposite="true" />
    <AdapterReference Name="MyPictureAdapter" Type="FullyQualifiedType2" field="true" event="true" />
    <AdapterReference Name="MyEventAdapter" Type="FullyQualifiedType3" eventComposite="true" />
    <AdapterReference Name="MyCommandAdapter" Type="FullyQualifiedType4" command="true" />
    <AdapterReference Name="MyCommandAdapter2" Type="FullyQualifiedType5" commandComposite="true" />
  </Adapters>
  <PhysicalView Name="ShoppingCartPhysicalViews.ShopingHome, ShoppingCartPhysicalViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" WorkUnit="" LogicalView="ShopingHome" Provider="Winform">
    <Fields>
      <Field Name="ProductTable" BiDirectional="false">
        <DirectMapping>Products</DirectMapping>
        <DirectMapping>Products2</DirectMapping>
      </Field>
      <Field Name="ProductSelect" BiDirectional="true">
        <DirectMapping>productselect.Text</DirectMapping>
        <AdapterMapping type="MyPictureAdapter" Init="MyPictureDb">productPicture.Picture</AdapterMapping>
      </Field>
      <Field Name="Price" BiDirectional="true">
        <DirectMapping>Price.Text</DirectMapping>
      </Field>
      <Field Name="Price.MaxValue" BiDirectional="false">
        <DirectMapping>PriceMax.Text</DirectMapping>
      </Field>
      <Adapter Type="MyAdapterName" BiDirectional="true" Init="">
        <Input Source="LogicalField" Id="0">ProductTable</Input>
        <Input Source="Constant" Id="1">1</Input>
        <Output Id="0">Products</Output>
        <Output Id="1">Products2</Output>
      </Adapter>
    </Fields>
    <Events>
      <Event Name="paymentshopping">
        <DirectHandler>button2.Click</DirectHandler>
        <DirectHandler>button2.Click</DirectHandler>
        <AdapterHandler type="MyPictureAdapter">productPicture</AdapterHandler>
      </Event>
      <Adapter Type="MyEventAdapter" Init="MyPictureDb">
        <Target Source="LogicalField" Id="0">productSelect</Target>
        <Target Source="Constant" Id="1">5</Target>
        <Handler>PaymentShopping</Handler>
      </Adapter>
    </Events>
  </PhysicalView>
  <PhysicalView Name="ShoppingCartPhysicalViews.ShopingPayment, ShoppingCartPhysicalViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" WorkUnit="" LogicalView="ShopingPayment" Provider="Winform">
    <Fields>
      <Field Name="CreditCardType" BiDirectional="true">
        <DirectMapping>creditCardTypesDropDown.Text</DirectMapping>
      </Field>
      <Field Name="CreditCardNumber" BiDirectional="true">
        <DirectMapping>CreditCardNumber.Text</DirectMapping>
      </Field>
    </Fields>
    <Events>
      <Event Name="back">
        <DirectHandler>button1.Click</DirectHandler>
      </Event>
    <CommandHandlers>
      <CommandHandler CommandName="FillDefaultValues">
        <DirectHandler>FillValue</DirectHandler>
        <AdapterHandler Type="MyCommandHandler" Init="MyInitString" >ExpiryDate</AdapterHandler>
      </CommandHandler>
      <Adapter Type="MyCommandAdapter" Init="MyPictureDb">
        <Target Source="LogicalField" Id="0">productSelect</Target>
        <Target Source="Constant" Id="1">5</Target>
        <Handler>FillDefaultValues</Handler>
      </Adapter>
    </CommandHandlers>
  </PhysicalView>
</PhysicalViewMappings> 

You must declare the adapters in a dedicated section, as shown below:

<Adapters>
<AdapterReference Name="MyAdapterName" Type="FullyQualifiedType" fieldComposite="true" />
<AdapterReference Name="MyPictureAdapter" Type="FullyQualifiedType2" field="true" event="true" />
<AdapterReference Name="MyEventAdapter" Type="FullyQualifiedType3" eventComposite="true" />
<AdapterReference Name="MyCommandAdapter" Type="FullyQualifiedType4" command="true" />
<AdapterReference Name="MyCommandAdapter2" Type="FullyQualifiedType5" commandComposite="true" />
</Adapters>

All adapters are identified by a fully qualified name, and also has a name assigned. Also the AdapterReference tag allows you to specify the adapter intended usage, as non-exclusive flags. You can use the adapter in any of the six modes, after declaration, based on the value assigned to the AdapterReference tag:

  • Field: If the Adapter is used for inline field binding
  • Fieldcomposite: If the Adapter is used for field binding with complex associations
  • Event: If the Adapter is used for inline event binding
  • EventComposite: If the Adapter is used for event binding with complex associations
  • Command: If the Adapter is used for inline command binding
  • CommandComposite: If the Adapter is used for command binding with complex associations