本文整理匯總了C#中System.Factory.ScanAssembly方法的典型用法代碼示例。如果您正苦於以下問題:C# Factory.ScanAssembly方法的具體用法?C# Factory.ScanAssembly怎麽用?C# Factory.ScanAssembly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Factory
的用法示例。
在下文中一共展示了Factory.ScanAssembly方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ExecutePlugin
private void ExecutePlugin(IEnumerable<string> args)
{
if (String.IsNullOrWhiteSpace(pluginPath))
{
throw new ArgumentException("Plugin assembly not specified");
}
if (!File.Exists(pluginPath))
{
throw new IOException("Plugin assembly not found");
}
var factory = new Factory<IPlugin>();
if (verbose)
{
Console.WriteLine("scanning plugin path: {0}", pluginPath);
}
try
{
factory.ScanAssembly(pluginPath);
}
catch (Exception e)
{
throw new Exception("Error loading plugin", e);
}
if (factory.Count == 0)
{
throw new Exception("Assembly does not contain any plugins");
}
if (verbose)
{
Console.WriteLine("found {0} plugin module(s)", factory.Count);
}
IPlugin p = null;
if (!String.IsNullOrWhiteSpace(pluginName))
{
try
{
p = factory.Make(pluginName);
}
catch (Exception e)
{
throw new Exception("Error creating plugin: " + pluginName, e);
}
if (verbose)
{
Console.WriteLine("using plugin module: {0}", pluginName);
}
}
else
{
try
{
p = (IPlugin)factory[0].Make();
}
catch (Exception e)
{
throw new Exception("Error creating default plugin: " + factory[0].ToString(), e);
}
if (verbose)
{
Console.WriteLine("using plugin module: {0}", Reflect.DisplayName(p));
}
}
if (p != null)
{
p.Execute(args);
}
}