|
|
|
@ -54,6 +54,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
@@ -54,6 +54,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
|
|
|
|
|
Library = 0x8, |
|
|
|
|
UseRoslyn = 0x10, |
|
|
|
|
UseMcs = 0x20, |
|
|
|
|
ReferenceVisualBasic = 0x40, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Flags] |
|
|
|
@ -181,10 +182,11 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
@@ -181,10 +182,11 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
|
|
|
|
|
return Regex.Replace(il, @"'<PrivateImplementationDetails>\{[0-9A-F-]+\}'", "'<PrivateImplementationDetails>'"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static readonly Lazy<IEnumerable<MetadataReference>> defaultReferences = new Lazy<IEnumerable<MetadataReference>>(delegate { |
|
|
|
|
string refAsmPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), |
|
|
|
|
static readonly string refAsmPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), |
|
|
|
|
@"Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2"); |
|
|
|
|
string thisAsmPath = Path.GetDirectoryName(typeof(Tester).Assembly.Location); |
|
|
|
|
static readonly string thisAsmPath = Path.GetDirectoryName(typeof(Tester).Assembly.Location); |
|
|
|
|
|
|
|
|
|
static readonly Lazy<IEnumerable<MetadataReference>> defaultReferences = new Lazy<IEnumerable<MetadataReference>>(delegate { |
|
|
|
|
return new[] |
|
|
|
|
{ |
|
|
|
|
MetadataReference.CreateFromFile(Path.Combine(refAsmPath, "mscorlib.dll")), |
|
|
|
@ -194,12 +196,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
@@ -194,12 +196,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
|
|
|
|
|
MetadataReference.CreateFromFile(Path.Combine(refAsmPath, @"Facades\System.Runtime.dll")), |
|
|
|
|
MetadataReference.CreateFromFile(Path.Combine(refAsmPath, "System.Xml.dll")), |
|
|
|
|
MetadataReference.CreateFromFile(Path.Combine(refAsmPath, "Microsoft.CSharp.dll")), |
|
|
|
|
MetadataReference.CreateFromFile(Path.Combine(refAsmPath, "Microsoft.VisualBasic.dll")), |
|
|
|
|
MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location), |
|
|
|
|
MetadataReference.CreateFromFile(typeof(Span<>).Assembly.Location), |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
static readonly Lazy<IEnumerable<MetadataReference>> visualBasic = new Lazy<IEnumerable<MetadataReference>>(delegate { |
|
|
|
|
return new[] { |
|
|
|
|
MetadataReference.CreateFromFile(Path.Combine(refAsmPath, "Microsoft.VisualBasic.dll")) |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
public static List<string> GetPreprocessorSymbols(CompilerOptions flags) |
|
|
|
|
{ |
|
|
|
|
var preprocessorSymbols = new List<string>(); |
|
|
|
@ -240,8 +247,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
@@ -240,8 +247,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
|
|
|
|
|
if (flags.HasFlag(CompilerOptions.UseRoslyn)) { |
|
|
|
|
var parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols.ToArray(), languageVersion: Microsoft.CodeAnalysis.CSharp.LanguageVersion.Latest); |
|
|
|
|
var syntaxTrees = sourceFileNames.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, path: f)); |
|
|
|
|
var references = defaultReferences.Value; |
|
|
|
|
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) { |
|
|
|
|
references = references.Concat(visualBasic.Value); |
|
|
|
|
} |
|
|
|
|
var compilation = CSharpCompilation.Create(Path.GetFileNameWithoutExtension(sourceFileName), |
|
|
|
|
syntaxTrees, defaultReferences.Value, |
|
|
|
|
syntaxTrees, references, |
|
|
|
|
new CSharpCompilationOptions( |
|
|
|
|
flags.HasFlag(CompilerOptions.Library) ? OutputKind.DynamicallyLinkedLibrary : OutputKind.ConsoleApplication, |
|
|
|
|
platform: flags.HasFlag(CompilerOptions.Force32Bit) ? Platform.X86 : Platform.AnyCpu, |
|
|
|
@ -328,7 +339,9 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
@@ -328,7 +339,9 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
|
|
|
|
|
options.ReferencedAssemblies.Add("System.Core.dll"); |
|
|
|
|
options.ReferencedAssemblies.Add("System.Xml.dll"); |
|
|
|
|
options.ReferencedAssemblies.Add("Microsoft.CSharp.dll"); |
|
|
|
|
options.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll"); |
|
|
|
|
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) { |
|
|
|
|
options.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll"); |
|
|
|
|
} |
|
|
|
|
CompilerResults results = provider.CompileAssemblyFromFile(options, sourceFileNames.ToArray()); |
|
|
|
|
if (results.Errors.Cast<CompilerError>().Any(e => !e.IsWarning)) { |
|
|
|
|
StringBuilder b = new StringBuilder("Compiler error:"); |
|
|
|
|