It is now possible to create optional package in C#. However, it is not clear how to invoke the code in the optional package from a C# UWP main app, especially if we need to invoke it in a generic fashion.
Say, I have a plugins within the optional package and they all implement IPlugin
interface with an Execute
method and Name
property. I would like to display the Name
s of all the plugins in a menu and invoke the Execute
method of plugin when user clicks on it.
We can iterate over all the optional packages of the main app, something like
// 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}");
}
}
How do I invoke the code that is present in these optional packages.