AutoWikiBrowser.CustomModule.MakeModule C# (CSharp) Method

MakeModule() public method

public MakeModule ( ) : void
return void
        public void MakeModule()
        {
            try
            {
                CompilerParameters cp = new CompilerParameters
                {
                    GenerateExecutable = false,
                    IncludeDebugInformation = false
                };

                // Microsoft.GeneratedCode check is for Mono compatibility
                foreach (
                    var path in
                        AppDomain.CurrentDomain.GetAssemblies()
                            .Where(
                                asm =>
                                    !asm.FullName.Contains("Microsoft.GeneratedCode") &&
                                    !asm.Location.Contains("mscorlib") &&
                                    !string.IsNullOrEmpty(asm.Location))
                            .Select(asm => asm.Location))
                {
                    cp.ReferencedAssemblies.Add(path);
                }

                CompilerResults results = Compiler.Compile(txtCode.Text, cp);

                bool hasErrors = false;
                if (results.Errors.Count > 0)
                {
                    StringBuilder builder = new StringBuilder(); // "Compilation messages:\r\n");
                    foreach (CompilerError err in results.Errors)
                    {
                        hasErrors |= !err.IsWarning;

                        if (err.Line > 0)
                            builder.AppendFormat("Line {0}, col {1}: ", err.Line, err.Column);

                        if (!string.IsNullOrEmpty(err.ErrorNumber))
                            builder.AppendFormat("[{0}] ", err.ErrorNumber);

                        builder.Append(err.ErrorText);
                        builder.Append("\r\n");
                    }

                    using (CustomModuleErrors error = new CustomModuleErrors())
                    {
                        error.ErrorText = builder.ToString();
                        error.Text = "Compilation " + (hasErrors ? "errors" : "warnings");
                        error.ShowDialog(this);
                    }

                    if (hasErrors)
                    {
                        Module = null;
                        return;
                    }
                }

                foreach (Type t in results.CompiledAssembly.GetTypes().Where(t => t.GetInterface("IModule") != null))
                {
                    Module = (IModule) Activator.CreateInstance(t, Program.AWB);
                }
            }
            catch (Exception ex)
            {
                Module = null;
                ErrorHandler.HandleException(ex);
            }
        }