2012-09-04 2 views

답변

2

당신은 어셈블리를로드 할 Assembly.LoadFrom 방법을 사용할 수 있습니다. 여기에서 reflection을 사용하여 라이브러리의 public 메소드를 호출 할 수 있습니다.

0

질문의 성격에 대한 질문이 더 많지 않지만 플러그인 유형 확장 성 이유로 어셈블리를로드하려는 경우 MEF (Managed Extensibility Framework)과 같은 라이브러리를 사용하는 것이 좋습니다. 이 MEF with Delphi Prism here 사용에 대한 간단한 포스트는, 그러나 당신이 인터페이스를 정의하고 다양한 방법으로 당신의 어셈블리를 사용할 수 있습니다 :

PluginList = class 
public 
    [ImportMany(typeof(IFileAction))] 
    property FileActions: IList<IFileAction> read write; 
    constructor; 
end; 

는 그런 다음로드 할 수 있습니다 : 당신이 당신의 인터페이스를 정의해야

우선

0 : 당신이 당신의 작업을 수행 할 수있는에 그런 다음로드 된 어셈블리의 목록을 가지고

var aggregateCat := new AggregateCatalog(); 
var catalogThisAssembly := new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()); 
var catalogIndividual := new AssemblyCatalog('plugins\MyHelloPlugin.dll'); 
var dirCatalog := new DirectoryCatalog('plugins'); 

// Add our Catalogs here, 
aggregateCat.Catalogs.Add(dirCatalog); 

var container := new CompositionContainer(aggregateCat); 
// Create our plugin hosting object 
var pluginList := new PluginList(); 
// Compose the parts. 
container.ComposeParts(pluginList); 

: 확장을위한 많은 어셈블리까지 서로 다른 여러 가지 방법으로 원하는대로

for each plugin: IFileAction in pluginList.FileActions do 
begin 
    Console.WriteLine('Loaded ' + plugin.Name + ', version ' + plugin.Version); 
end;