现在可以在 C# 中创建可选包。但是,尚不清楚如何从 C# UWP 主应用程序调用可选包中的代码,尤其是当我们需要以通用方式调用它时。
比如说,我在可选包中有一个插件,它们都实现IPlugin
了带有Execute
方法和Name
属性的接口。我想Name
在菜单中显示所有插件的 s 并Execute
在用户单击它时调用插件的方法。
我们可以遍历主应用程序的所有可选包,例如
// Obtain the app's package first to then find all related packages
var currentAppPackage = Windows.ApplicationModel.Package.Current;
// The dependencies list is where the list of optional packages (OP) can be determined
var dependencies = currentAppPackage.Dependencies;
for (var package in dependencies)
{
// If it is optional, then add it to our results vector
if (package.IsOptional)
{
WriteLine("Optional Package found - {package.Id.FullName}");
}
}
如何调用这些可选包中存在的代码。