Game Development Reference
In-Depth Information
{
List<Type> pluginTypes = new List<Type>();
List<PluginInfo> pluginInfo = new List<PluginInfo>();
List<IPlugin> pluginInstances = new List<IPlugin>();
The following method is used to load a plugin assembly into a temporary
AppDomain and build a collection of information about each class that implements
the IPlugin interface.
public bool LoadAssembly(AppDomain appDomain, byte[] data)
{
try
{
Assembly assembly = appDomain.Load(data);
foreach (Type type in assembly.GetTypes())
{
if (!type.IsAbstract)
{
foreach (Type interfaceType in type.GetInterfaces())
{
if (interfaceType == typeof(IPlugin) &&
type.IsDefined(typeof(PluginAttribute), false))
{
pluginTypes.Add(type);
PluginAttribute pluginAttrib =
type.GetCustomAttributes(typeof(PluginAttribute),
false)[0] as PluginAttribute;
As mentioned earlier, it is important that the proxy does not return any of the
types within the plugin library. We want users to be able to view the plugin
attribute information about each plugin, so the following two lines instantiate a
wrapper class designed to hold the attribute information.
PluginInfo info = new PluginInfo(pluginAttrib.Component,
pluginAttrib.Description);
pluginInfo.Add(info);
}
}
}
}
Search Nedrilad ::




Custom Search