Game Development Reference
In-Depth Information
private FileInfo[] GetPluginFiles(DirectoryInfo pluginDirectory)
{
FileInfo[] plugins;
if (pluginDirectory.Exists)
{
List<FileInfo> filteredPlugins = new List<FileInfo>();
filteredPlugins.AddRange(pluginDirectory.GetFiles(“*.dll”));
filteredPlugins.AddRange(pluginDirectory.GetFiles(“*.cs”));
filteredPlugins.AddRange(pluginDirectory.GetFiles(“*.vb”));
filteredPlugins.AddRange(pluginDirectory.GetFiles(“*.js”));
plugins = filteredPlugins.ToArray();
}
else
{
pluginDirectory.Create();
plugins = new FileInfo[0];
}
return plugins;
}
}
}
Runtime Compilation of Plugins
Plugins are an excellent way to extend an application without the need to recom-
pile the application. However, the plugins themselves must be recompiled when
modified, and the new version must then be deployed to the installation applica-
tions. We can try to improve this by introducing a runtime plugin compiler into
the solution. Doing so will allow us to place source code files in the plugins direc-
tory and have them loaded into the application at runtime as compiled assemblies.
Obviously, you would only want to use this feature in a trusted environment. In
fact, the security policy introduced in this chapter will not permit this kind of code
to execute without readjusting the default settings.
The following code shows the full source code to the plugin factory that is used to
compile plugins at runtime. The only real functionality is in CompilePluginSource() ,
where the appropriate CodeDom compiler is created, and many of the most commonly
used class framework libraries are referenced so that they are available to the plugins.
Search Nedrilad ::




Custom Search