Code Snippet
///
/// Implements the OnConnection method of the IDTExtensibility2 interface.
/// Receives notification that the Add-in is being loaded.
///
///
/// Root object of the host application.
///
///
/// Describes how the Add-in is being loaded.
///
///
/// Object representing this Add-in.
///
///
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
string applicationName = GetProperty(ref applicationObject, "Name");
string applicationVersion = GetProperty(ref applicationObject, "Version");
MessageBox.Show(string.Format("AddIn loaded within: {0} Version: {1}.", applicationName, applicationVersion));
}
///
/// Returns a property with the given Name latebound as the given type.
///
/// The targetType
/// The object where to retrieve the property from.
/// The Name of the property.
/// returns the specific value or throws an error.
private T GetProperty(ref object target, string propertyName)
{
return (T)target.GetType().InvokeMember(propertyName, BindingFlags.GetProperty, null, target, null);
}