Inherit this abstract class to create a custom extension.

Namespace:  ESRI.ArcGIS.Desktop.AddIns

Assembly:  ESRI.ArcGIS.Desktop.Addins (in ESRI.ArcGIS.Desktop.Addins.dll) Version: 10.0.0.0 (10.0.0.0)

Syntax

C#
public abstract class Extension : IDisposable
Visual Basic (Declaration)
Public MustInherit Class Extension _
	Implements IDisposable
Visual C++
public ref class Extension abstract : IDisposable

Remarks

Application extension is used to coordinate activities between other components such as buttons, tools and dockable windows within a containing add-in. It is usually responsible for storing state associated with the add-in as a whole, and is often used to listen for and respond to various events exposed by the host application. Application extension can be configured through xml to load when needed or automatically when their associated application is started by setting autoLoad attribute in the add-in xml; extension can also be configured to appear in the standard ArcGIS extension dialog by setting showInExtensionDialog to true in the add-in xml. Application extension can write data directly into map documents. This is useful to developers who want to re-establish state on a per document basis.

Examples

The code below shows an extension class that writes a private data structure which manages an ArcObjects type.
CopyC#
//  Need to add reference to ESRI.ArcGIS.ADF.Local assembly.
//  using System;
//  using System.Collections.Generic;
//  using System.IO;
//  using ESRI.ArcGIS.ADF.Serialization;
  public class LogExtension : ESRI.ArcGIS.Desktop.AddIns.Extension
  {
    private MyPersistentData _data;

    [Serializable()]
    private struct MyPersistentData
    {
      public string Location;
      public string UserName;
      public ESRI.ArcGIS.Geometry.PointClass Point;
    }

    public LogExtension()
    {
    }

    protected override void OnStartup()
    {
      ArcMap.Events.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(Events_OpenDocument);
    }

    protected override void OnShutdown()
    {
      _data.Point = null;
    }

    void Events_OpenDocument()
    {
      string logText = _data.Location + " ( " + _data.Point.X + ", " + _data.Point.Y + " )" + "\n UserName: " + _data.UserName;
      System.Windows.Forms.MessageBox.Show(logText);
    }

    protected override void OnSave(Stream outStrm)
    {
      //Get called when saving document.
      _data = new MyPersistentData();
      _data.Location = "Home";
      _data.UserName = Environment.UserName;
      _data.Point = new ESRI.ArcGIS.Geometry.PointClass();
      _data.Point.X = 100;
      _data.Point.Y = 200;

      PersistenceHelper.Save<MyPersistentData>(outStrm, _data);
    }

    protected override void OnLoad(Stream inStrm)
    {
      //Get called when opening a document with persisted stream.

      //Initialize the struct
      _data.Location = "";
      _data.Point = new ESRI.ArcGIS.Geometry.PointClass();
      PersistenceHelper.Load<MyPersistentData>(inStrm, ref _data);
    }
  }
CopyVB.NET
' Need to add reference to ESRI.ArcGIS.ADF.Local assembly. 
' using System; 
' using System.Collections.Generic; 
' using System.IO; 
' using ESRI.ArcGIS.ADF.Serialization; 
Public Class LogExtension
  Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
  Private _data As MyPersistentData

  <Serializable()> _
  Private Structure MyPersistentData
    Public Location As String
    Public UserName As String
    Public Point As ESRI.ArcGIS.Geometry.PointClass
  End Structure

  Public Sub New()
  End Sub

  Protected Overloads Overrides Sub OnStartup()
    AddHandler ArcMap.Events.OpenDocument, AddressOf Events_OpenDocument
  End Sub

  Protected Overloads Overrides Sub OnShutdown()
    _data.Point = Nothing
  End Sub

  Private Sub Events_OpenDocument()
    Dim logText As String = (((_data.Location & " ( ") + _data.Point.X & ", ") + _data.Point.Y & " )" & vbLf & " UserName: ") + _data.UserName
    System.Windows.Forms.MessageBox.Show(logText)
  End Sub

  Protected Overloads Overrides Sub OnSave(ByVal outStrm As Stream)
    'Get called when saving document. 
    _data = New MyPersistentData()
    _data.Location = "Home"
    _data.UserName = Environment.UserName
    _data.Point = New ESRI.ArcGIS.Geometry.PointClass()
    _data.Point.X = 100
    _data.Point.Y = 200

    PersistenceHelper.Save(Of MyPersistentData)(outStrm, _data)
  End Sub

  Protected Overloads Overrides Sub OnLoad(ByVal inStrm As Stream)
    'Get called when opening a document with persisted stream. 


    'Initialize the struct 
    _data.Location = ""
    _data.Point = New ESRI.ArcGIS.Geometry.PointClass()
    PersistenceHelper.Load(Of MyPersistentData)(inStrm, _data)
  End Sub
End Class

Inheritance Hierarchy

System..::.Object

  ESRI.ArcGIS.Desktop.AddIns..::.Extension

See Also