Exemple #1
0
        private void CheckForFixup(CommandLineResults results)
        {
            if (results.Fixup == true)
            {
                //  Find the output location
                string currentLocation = results.Parameters.OutputAssembly;

                //  Find the main method and its' corresponding class.
                Assembly currentAssembly = Assembly.LoadFrom(
                    currentLocation);

                string mainClass = currentAssembly.EntryPoint.DeclaringType.Name;

                //  Move the file to its' new location w/ its' new name.
                string newFile = Path.Combine(Directory.GetCurrentDirectory(),
                                              string.Format("{0}.exe", mainClass));

                if (File.Exists(newFile) == true)
                {
                    File.Delete(newFile);
                }

                File.Move(currentLocation, newFile);

                results.Parameters.OutputAssembly = newFile;
            }
        }
Exemple #2
0
        public ECProvider(CommandLineResults cmdLineResults) : base()
        {
            //  PRECONDITION: cmdLineResults != null.
            if (cmdLineResults == null)
            {
                throw new ArgumentNullException(PARAM_CMD_LINE_RESULTS);
            }

            this.mCmdLineResults = cmdLineResults;
        }
Exemple #3
0
        public ECCompiler(ICodeCompiler compiler, CommandLineResults cmdLineResults)
        {
            //  PRECONDITION: compiler != null.
            if (compiler == null)
            {
                throw new ArgumentNullException(PARAM_COMPILER);
            }

            this.mCompiler       = compiler;
            this.mCmdLineResults = cmdLineResults;
        }
Exemple #4
0
        private bool IsExceptionCatchingOK(CommandLineResults cmdResults,
                                           CompilerResults results)
        {
            bool retVal = true;
            //  Look at the assembly and go through each of the types and
            //  their corresponding methods.
            Assembly newAssembly = results.CompiledAssembly;

            //  For each method, parse the CIL, and look for call, calli, and
            //  callvirt calls. If that method is tagged with [Throws],
            //  it must be caught or the method itself must be tagged.
            Type[] assemblyTypes = newAssembly.GetTypes();

            foreach (Type t in assemblyTypes)
            {
                BindingFlags methodBinding = BindingFlags.Public |
                                             BindingFlags.NonPublic | BindingFlags.Instance |
                                             BindingFlags.Static;

                MethodInfo[] typeMethods = t.GetMethods(methodBinding);

                if (typeMethods != null && typeMethods.Length > 0)
                {
                    foreach (MethodInfo mi in typeMethods)
                    {
                        UnhandledExceptions uEx = new UnhandledExceptions(mi);

                        if (uEx.ExceptionList.Count > 0)
                        {
                            //  We need to report this to the user.
                            retVal = false;

                            foreach (Type ex in uEx.ExceptionList)
                            {
                                results.Errors.Add(new CompilerError(newAssembly.Location,
                                                                     0, 0, ERROR_UNHANDLED_EXCEPTION_CODE,
                                                                     string.Format(ERROR_UNHANDLED_EXCEPTION_DESCRIPTION,
                                                                                   mi.Name, t.Name, ex.FullName)));
                            }
                        }
                    }
                }
            }

            return(retVal);
        }