IVsExtensionManager.CreateExtension-Methode
factory Methode des Add-Ins.
Namespace: Microsoft.VisualStudio.ExtensionManager
Assembly: Microsoft.VisualStudio.ExtensionManager (in Microsoft.VisualStudio.ExtensionManager.dll)
Syntax
'Declaration
Function CreateExtension ( _
extensionPath As String _
) As IExtension
IExtension CreateExtension(
string extensionPath
)
IExtension^ CreateExtension(
String^ extensionPath
)
abstract CreateExtension :
extensionPath:string -> IExtension
function CreateExtension(
extensionPath : String
) : IExtension
Parameter
extensionPath
Typ: StringPfad eine VSIX-Manifestdatei.
Rückgabewert
Typ: Microsoft.VisualStudio.ExtensionManager.IExtension
Das IExtension-Objekt, das die Metadaten im VSIX-Manifest für eine Erweiterung enthält.
Hinweise
Obwohl dies Erweiterungs-Manager API unterstützt die Infrastruktur wir empfiehlt, dass Sie sie nicht verwenden, da sie ggf. geändert wird.
Beispiele
Im folgenden Beispiel wird GetEnabledExtensionContentLocations, um die Speicherorte aller Erweiterungen eines bestimmten benutzerdefinierten Typs abzurufen. Anschließend wird mithilfe CreateExtension, um die andere Metadaten für jede gefundene Erweiterung zugreifen und ihren Namen abzurufen. Nachdem es die Namen und die Pfadinformationen speichert, erstellt er Menübefehle für jede Erweiterung.
// This is the CommandID of the placeholder menu item,
// as defined in the .vsct file.
int CmdIdBase = 0x103;
// These lists will store name and path information.
private ArrayList SkinNames = new ArrayList();
private ArrayList SkinPaths = new ArrayList();
// Call this from Initialize().
private void InitSkinList()
{
var mcs = GetService(typeof(IMenuCommandService))
as OleMenuCommandService;
int counter = CmdIdBase;
// Get the Extension Manager service.
var ExtMgrSvc = GetService(typeof(SVsExtensionManager))
as IVsExtensionManager;
// Iterate through installed extensions.
var attributes = new Dictionary<string, string>();
attributes.Add("Type", "Skin");
foreach (string SkinPath
in ExtMgrSvc.GetEnabledExtensionContentLocations(
"CustomExtension", attributes))
{
// Store the name and path information.
SkinPaths.Add(SkinPath);
SkinNames.Add(ExtMgrSvc.CreateExtension(SkinPath).Header.Name);
// Create a CommandID for the new menu item.
var cmdID = new CommandID(
GuidList.guidVSSkinHostCmdSet, counter);
// Create the menu item and add its event handlers.
var mc = new OleMenuCommand(
new EventHandler(OnSkinExec), cmdID);
mc.BeforeQueryStatus += new EventHandler(OnSkinQueryStatus);
mcs.AddCommand(mc);
counter ++;
}
}
private void OnSkinQueryStatus(object sender, EventArgs e)
{
var menuCommand = sender as OleMenuCommand;
if (null != menuCommand)
{
// Determine which menu item was queried.
int skinIndex = menuCommand.CommandID.ID - this.CmdIdBase;
if (skinIndex >= 0 && skinIndex < this.SkinNames.Count)
{
// Set the text.
menuCommand.Text = this.SkinNames[skinIndex] as string;
}
}
}
private void OnSkinExec(object sender, EventArgs e)
{
var menuCommand = sender as OleMenuCommand;
if (null != menuCommand)
{
// Get the name of the skin from the menu item.
string skinName = menuCommand.Text;
// Locate the name in the list of skins.
int i = this.SkinNames.IndexOf(skinName);
// Get the corrsponding path.
var skinPath = SkinPaths[i] as string;
if (SkinNames.Count > 0)
{
if (File.Exists(skinPath) || Directory.Exists(skinPath))
{
// Put code here to apply the skin extension...
MessageBox.Show("Skin " + skinName + " found:\r\n"
+ skinPath + ". \r\n\r\nApplying skin...");
}
else MessageBox.Show("Could not find skin " + skinName);
}
}
}
.NET Framework-Sicherheit
- Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter Verwenden von Bibliotheken aus teilweise vertrauenswürdigem Code.