Serializing add-in properties

When an operation view is saved, values stored in properties in a widget or map tool can be serialized to the JSON of the operation view, by applying serialization attributes to the class and members. Most common value types can be serialized and deserialized in this way, but most reference types cannot.

DataContract and DataMember attributes

Operations Dashboard for ArcGIS serializes the state of an operation view when it is saved by using some of the functionality provided in the System.Runtime.Serialization namespace. Declaring the DataContract attribute on a class indicates that it should be serialized, as it contains data that should be saved when an operation view is saved, and then deserialized again when the view is reopened. Declaring the DataMember on a field or property indicates that its value should be serialized as part of this process; properties without this attribute will not be serialized.

For example, the IDataSourceConsumer.DataSourceIds property created by the widget item template has the attribute applied, as this value should be serialized to ensure the same data source is identified when the view is re-opened.

NoteNote:

The values of feature actions are not serialized in this way. See the Serializing feature actions hosted in a widget section below for more details.

How to serialize properties

  1. On the widget or map tool class, ensure the System.Runtime.Serialization.DataContract attribute is declared.

    DataContract attribute C# example

    [System.Runtime.Serialization.DataContract]
    public partial class MyWidget : UserControl, IWidget
    

    DataContract attribute Visual Basic example

    <System.Runtime.Serialization.DataContract> _
    Partial Public Class MyWidget
      Inherits UserControl
      Implements IWidget
    
  2. On each valid type of property whose value should be serialized, declare the System.Runtime.Serialization.DataMember attribute.

    DataMember attribute C# example

    [DataMember(Name = "id")]
    public string Id
    

    DataMember attribute Visual Basic example

    <DataMember(Name:="id")> _
    Public Property Id As String Implements IWidget.Id
    
    NoteNote:

    Most value types can be serialized. See the section below for more information.

Types that can be serialized

Operations Dashboard for ArcGIS uses it's own internal serializer class. This can be used to serialize and deserialize properties declared as the following types:

  • Boolean
  • Byte
  • 32 and 64 bit Integer
  • Double
  • String
  • System.Windows.Media.Color
  • Enumerations
  • ESRI.ArcGIS.Client.Geometry.PointCollection

Serializing feature actions hosted in a widget

The properties of feature actions are not serialized automatically when you save a view, as describe above for widgets and map tools. To save properties of a feature action, the values must be serialized and deserialized as part of the widget in which the feature action is hosted.

For an example, see the Widget with feature actions sample.

1/27/2015