Pitney Bowes MapXtreme User Manual

Page 513

Advertising
background image

Appendix D: Extensible Data Providers

Advanced Topics / Important Considerations

MapXtreme v7.1

520

Developer Guide

The IDataSource reference within the ITable should not be serialized as MapXtreme will take care of
automatically serializing the datasource for the table.

Shared object references are re-established via the serialization logic provided by MapXtreme. The
extensible data provider API contains the hooks necessary for the core MapXtreme data access
engine to accomplish this work. Specific examples include:

The ReAssociate method on the IDataProvider interface

The settable DataSourceDefinition property on the ITableDefinition interface

Implementing Serialization

Classes are serialized by being tagged with the [Serializable] attribute or by implementing the
System.Runtime.Serialization.ISerializable interface. We recommend you do both. The
ISerializable.GetObjectData method must be implemented and it must be public:

public void GetObjectData(SerializationInfo info, StreamingContext
context)

For classes derived from the abstract base classes, this signature should also contain the override
keyword, and the first line of the implementation should delegate to the base class for serialization of
the components it is managing. For example:

base.GetObjectData(info, context);

The remaining serializable members within the instance are serialized into the SerializationInfo
argument named info by providing a string key and the member value to its AddValue method. For
example:

info.AddValue("TableName", _tableName);

Implementing Deserialization

To support deserialization, provide a protected deserialization constructor whose arguments match
those on GetObjectData above. For example:

protected COTWTableDefinition(SerializationInfo info, StreamingContext
ctxt)

For classes derived from the abstract base classes, this constructor should delegate to the base
class for deserialization of the components it is managing. For example:

protected COTWTableDefinition(SerializationInfo info, StreamingContext
ctxt) : base(info, ctxt)

Within this constructor, the class instance assigns its member variables by retrieving values using
the “get” methods available on the SerializationInfo argument named info. For example, to
deserialize the TableName value serialized in the GetObjectData example above, the code might
resemble the following:

_tableName = info.GetString("TableName");

There are different recommendations regarding override support, method attributes, etc., for
methods pertaining to serialization depending, at least in part, upon whether or not the implementing
classes are sealed. Using a code analysis tool like FxCop can provide valuable assistance in
providing proper recommendations.

Advertising