本文整理汇总了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);
}
}