Codedom analysis (below)
It is compiled later. At the time of generating, starting from generatecodefromCompileUnit (), several other methods in iCodeGenerator can be called; in iCODeCompiler, the methods in the interface will last call to such a fromfilebatch () method. That look at how this method is implemented in the codecompiler:
protected
Virtual
CompilerResults fromfilebatch (CompilerParameters Options,
String
Filenames)
{...... .// slightly in front of some of the processing string text3 = this.CmdArgsFromParameters (options) "" CodeCompiler.JoinStringArray (fileNames, ""); string text4 = this.GetResponseFileCmdArgs (options, text3); string text5 = null; IF (text4! = null) {text5 = text3; text3 = text4;} this.Compile (options, executor.getruntimeInstallDirectory (), this.compilername, text3, ref text1, ref num1, text5); ... // below The processing of compilation results, omitted}
The problem is in this.compile () here, then find the roots:
Internal
Void
Compile (CompilerParameters Options,
String
CompilerDirectory,
String
CompileRexe,
String
Arguments,
Ref
String
Outputfile,
Ref
int
NativeReturnValue,
String
Trueargs)
{...... string text2 = compilerDirectory compilerExe; ...... nativeReturnValue = Executor.ExecWaitWithCapture (options.UserToken, "/" " text2 " / "" arguments, options.TempFiles, ref outputFile, ref text1, text3); ... ...}
Come out of a new thing EXECUTOR, the executor? That's this, calling command line compile is what it is doing, and CodeCompiler just provides a command line string. Executor is the Sealed class published in System.Codedom.compiler, all of which are some static methods, chase chasing, and finally here:
Private
Static
int
Execwaitwithcaptureunimpersonated (INTPTR USERTOKEN,
String
CMD,
String
Currentdir, TempFileCollection TempFiles,
Ref
String
OutputName,
Ref
String
ErrorName,
String
Truecmdline
. {...... flag1 = UnsafeNativeMethods.CreateProcess (null, new StringBuilder (cmd), null, null, true, 0, new HandleRef (null, ptr4), currentDir, startupinfo1, process_information1);. ...... int num2 = SafeNativeMethods.WaitForSingleObject (new HandleRef (null, process_information1.hProcess), 600000);. ...... if (! UnsafeNativeMethods.GetExitCodeProcess (new HandleRef (null, process_information1.hProcess), ref num3)) {......} return num3; ......}.
Familiar things, what creteProcess, WaitforsingleObject. Run to SafenativeMethods (or unsafenativeMethods), there is a lot of familiar faces, many [dllimport ()]. It turns out that there is nothing new in .Net.
The above things followed by a little relationship with Provider. But not right, how do it find the compiler when compiling? Provider is definitely role here. The third parameter of this.compile (): this.compilername, this is an abstract property, the specific value is available in the relevant provier. Note that CsharPcodegenerator class is inherited from CodeCompiler. Here is a more interesting inheritance relationship:
Public Abstract Class CodeGenerator: icodegenerator
Public Abstract Class CodeCompiler: CodeGenerator, icodecompiler
Internal Class Csharpcodegenerator: CodeCompiler
It is not interesting, but the name is more interesting. Csharpcodegenerator This class is originally included in the generation and compilation function. The attribute value of the compilername is provided in the CSHARPCODEGENERATOR, as if it is a bit chaos (it seems It's always thinking that CodeCompiler inherited from the CodeGenerator inheritance to the back Csharpcodegenerator, in the CodeCompiler, did not change the CodeGenerator, and a brain was thrown into the CSharpcodegenerator.). I didn't pay attention to this inheritance, and I didn't pay attention to the attribute value such as CompilerName in Csharpcodegenerator (Tibet it too, I have to go out of the scroll bar), how to get it, how to get it? solution.
Compiled things also get it.
The three major interfaces in System.Codedom.compiler go to the second, and there is an icodeparser no one, MS does not provide the corresponding implementation, and it has been seen in the Internet. Very scary thing, complex string analysis, whole section of Switch. Described two eyes, still did not jump in.