コード例 #1
0
ファイル: CSharpTestBase.cs プロジェクト: SkightTeam/roslyn
        public CompilationVerifier CompileWithCustomILSource(string cSharpSource, string ilSource, Action <CSharpCompilation> compilationVerifier = null, bool importInternals = true, EmitOptions emitOptions = EmitOptions.All, string expectedOutput = null)
        {
            var compilationOptions = importInternals ?
                                     ((expectedOutput != null) ? TestOptions.ExeAlwaysImportInternals : TestOptions.DllAlwaysImportInternals) :
                                     ((expectedOutput != null) ? TestOptions.Exe : TestOptions.Dll);

            if (ilSource == null)
            {
                var c = CreateCompilationWithMscorlib(cSharpSource, compOptions: compilationOptions);
                return(CompileAndVerify(c, emitOptions: emitOptions, expectedOutput: expectedOutput));
            }

            MetadataReference reference = null;

            using (var tempAssembly = SharedCompilationUtils.IlasmTempAssembly(ilSource))
            {
                reference = new MetadataImageReference(ReadFromFile(tempAssembly.Path));
            }

            var compilation = CreateCompilationWithMscorlib(cSharpSource, new[] { reference }, compilationOptions);

            if (compilationVerifier != null)
            {
                compilationVerifier(compilation);
            }

            return(CompileAndVerify(compilation, emitOptions: emitOptions, expectedOutput: expectedOutput));
        }
コード例 #2
0
        public CompilationVerifier CompileWithCustomILSource(string cSharpSource, string ilSource, Action <CSharpCompilation> compilationVerifier = null, bool importInternals = true, string expectedOutput = null)
        {
            var compilationOptions = (expectedOutput != null) ? TestOptions.ReleaseExe : TestOptions.ReleaseDll;

            if (importInternals)
            {
                compilationOptions = compilationOptions.WithMetadataImportOptions(MetadataImportOptions.Internal);
            }

            if (ilSource == null)
            {
                var c = CreateCompilationWithMscorlib(cSharpSource, options: compilationOptions);
                return(CompileAndVerify(c, expectedOutput: expectedOutput));
            }

            MetadataReference reference = null;

            using (var tempAssembly = SharedCompilationUtils.IlasmTempAssembly(ilSource))
            {
                reference = MetadataReference.CreateFromImage(ReadFromFile(tempAssembly.Path));
            }

            var compilation = CreateCompilationWithMscorlib(cSharpSource, new[] { reference }, compilationOptions);

            if (compilationVerifier != null)
            {
                compilationVerifier(compilation);
            }

            return(CompileAndVerify(compilation, expectedOutput: expectedOutput));
        }