Game Development Reference
private FileInfo GetPluginFiles(DirectoryInfo pluginDirectory)
List<FileInfo> filteredPlugins = new List<FileInfo>();
plugins = filteredPlugins.ToArray();
plugins = new FileInfo;
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.