Beispiel #1
0
 public static MetadataReference CreateMetadataReferenceFromIlSource(string ilSource)
 {
     using (var tempAssembly = IlasmUtilities.CreateTempAssembly(ilSource))
     {
         return(MetadataReference.CreateFromImage(ReadFromFile(tempAssembly.Path)));
     }
 }
Beispiel #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 = CreateStandardCompilation(cSharpSource, options: compilationOptions);
                return(CompileAndVerify(c, expectedOutput: expectedOutput));
            }

            MetadataReference reference = null;

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

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

            compilationVerifier?.Invoke(compilation);

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