FlatRedBall.Glue.Plugins.PluginManagerBase.CompilePlugin C# (CSharp) Method

CompilePlugin() private method

private CompilePlugin ( string filepath ) : CompilerResults
filepath string
return System.CodeDom.Compiler.CompilerResults
        private CompilerResults CompilePlugin(string filepath)
        {
            bool hasCs = System.IO.Directory.GetFiles(filepath).Any(item => FileManager.GetDirectory(item) == "cs");

            if(!hasCs)
            {
                return null;
            }

            CompilePluginOutput("Attempting to compile plugin : " + filepath);

            //Reference types to force assembly load
            const TextureProcessorOutputFormat texture = TextureProcessorOutputFormat.Color;
            using (new ZipFile()) { }

            texture.ToString();// We do this to eliminate "is never used" warnings

            string whyIsntCompatible = GetWhyIsntCompatible(filepath);

            if (string.IsNullOrEmpty(whyIsntCompatible))
            {
                LoadExternalReferenceList(filepath);

                string output;
                string name = Assembly.GetEntryAssembly().GetName().Name;
                PluginCompiler.Compiler.Path = System.IO.Path.GetTempPath() + name + @"Compiled\";
                string details;
                // need to fix this, or pass it a root folder or something.
                CompilerResults results = PluginCompiler.Compiler.CompilePlugin(
                    filepath,
                    mReferenceListInternal,
                    mReferenceListLoaded,
                    mReferenceListExternal,
                    out details);

                // Make sure a non-null result was returned
                if (results == null)
                {
                    return null;
                }

                string outputString = "";
                foreach (string s in results.Output)
                {
                    outputString += s + "   ";
                }

                string errorString = "";
                foreach (var s in results.Errors)
                {
                    errorString += s.ToString() + "   ";
                }

                if (!results.Errors.HasErrors && results.CompiledAssembly != null)
                {
                    Type[] types = results.CompiledAssembly.GetTypes();

                    bool foundAnExportedType = false;
                    foreach(Type type in types)
                    {
                        var attributes = type.GetCustomAttributes(typeof(ExportAttribute), true);

                        if (attributes != null && attributes.Length > 0)
                        {
                            foundAnExportedType = true;
                            break;
                        }
                    }

                    if (!foundAnExportedType)
                    {
                        CompilePluginError("Could not find any plugins with the [Export] tag for plugin than " + filepath);
                    }
                }

                string message = null;
                // I don't think we care about this anymore - it just clutters output a ton
                    //"Plugin compile output: " + outputString;
                if (!string.IsNullOrEmpty(errorString))
                {
                    message += "Compile errors: " + errorString;
                }

                CompilePluginError(message);
                return results;
            }
            else
            {
                CompilePluginOutput("Error on plugin in folder " + filepath + " : " + whyIsntCompatible);
            }

            return null;
        }