Ejemplo n.º 1
0
        /// <summary>
        /// Gets the object extended by this extension
        /// </summary>
        /// <returns>
        /// The extended object can be an <see cref="ExtensionPoint"/> or
        /// an <see cref="ExtensionNodeDescription"/>.
        /// </returns>
        /// <remarks>
        /// This method only works when the add-in description to which the extension belongs has been
        /// loaded from an add-in registry.
        /// </remarks>
        public ObjectDescription GetExtendedObject()
        {
            AddinDescription desc = ParentAddinDescription;

            if (desc == null)
            {
                return(null);
            }
            ExtensionPoint ep = FindExtensionPoint(desc, path);

            if (ep == null && desc.OwnerDatabase != null)
            {
                foreach (Dependency dep in desc.MainModule.Dependencies)
                {
                    AddinDependency adep = dep as AddinDependency;
                    if (adep == null)
                    {
                        continue;
                    }
                    Addin ad = desc.OwnerDatabase.GetInstalledAddin(ParentAddinDescription.Domain, adep.FullAddinId);
                    if (ad != null && ad.Description != null)
                    {
                        ep = FindExtensionPoint(ad.Description, path);
                        if (ep != null)
                        {
                            break;
                        }
                    }
                }
            }
            if (ep != null)
            {
                string subp = path.Substring(ep.Path.Length).Trim('/');
                if (subp.Length == 0)
                {
                    return(ep);                    // The extension is directly extending the extension point
                }
                // The extension is extending a node of the extension point

                return(desc.FindExtensionNode(path, true));
            }
            return(null);
        }