This is not problem at all, take a look at my sample code.
Here is abstract class that exists in separate dll:
public abstract class ServerTask
{
public int TaskId { get; set;}
/// <summary>
/// Gets description for ServerTask
/// </summary>
public abstract string Description { get; }
}
This is code from plugin implementation:
public class SampleTask : GP.Solutions.WF.Entities.Tasks.ServerTask
{
public override string Description
{
get
{
return "Sample plugin";
}
}
}
And finally code from core application that loads plugin:
/// <summary>
/// Loads Plugin from file
/// </summary>
/// <param name="fileName">Full path to file</param>
/// <param name="lockFile">Lock loaded file or not</param>
/// <returns></returns>
static Entities.Tasks.ServerTask LoadServerTask(string fileName, bool lockFile, int taskId)
{
Assembly assembly = null;
Entities.Tasks.ServerTask serverTask = null;
if (lockFile)
{
assembly = System.Reflection.Assembly.LoadFile(fileName);
}
else
{
byte[] data = Services.Common.ReadBinaryFile(fileName);
assembly = System.Reflection.Assembly.Load(data);
}
Type[] types = assembly.GetTypes();
foreach (Type t in types)
{
if (t.IsSubclassOf(typeof(Entities.Tasks.ServerTask)))
{
serverTask = (Entities.Tasks.ServerTask)Activator.CreateInstance(t);
serverTask.TaskId = taskId;
break;
}
}
if (serverTask == null)
{
throw new Exception("Unable to initialize to ServerTask type from library '" + fileName + "'!");
}
return serverTask;
}
If you are not familiar with c# just use c# to vb.net online converter.
Happy coding and best regards!
Gregor Primar
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…