Browse Source

Merge pull request #1866 from icsharpcode/netstandard2.1-fixes

netstandard2.1 fixes
pull/1880/head
Siegfried Pammer 6 years ago committed by GitHub
parent
commit
bb99896864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs
  3. 11
      ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs
  4. 4
      ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs
  5. 26
      ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

9
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -1044,9 +1044,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -1044,9 +1044,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
if (isDouble)
mathType = compilation.FindType(typeof(Math));
else {
mathType = compilation.FindType(new TopLevelTypeName("System", "MathF")).GetDefinition();
if (mathType == null || !mathType.GetFields(f => f.Name == "PI" && f.IsConst).Any() || !mathType.GetFields(f => f.Name == "E" && f.IsConst).Any())
mathType = compilation.FindType(new TopLevelTypeName("System", "MathF"));
var typeDef = mathType.GetDefinition();
if (typeDef == null
|| !typeDef.IsDirectImportOf(compilation.MainModule)
|| !typeDef.GetFields(f => f.Name == "PI" && f.IsConst).Any() || !typeDef.GetFields(f => f.Name == "E" && f.IsConst).Any())
{
mathType = compilation.FindType(typeof(Math));
}
}
expr = TryExtractExpression(mathType, type, constantValue, "PI", isDouble)

2
ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Metadata
{
var inst = This();
if (inst.PublicKeyOrToken.IsNil)
return Empty<byte>.Array;
return null;
var bytes = Module.Metadata.GetBlobBytes(inst.PublicKeyOrToken);
if ((inst.Flags & AssemblyFlags.PublicKey) != 0) {
return sha1.ComputeHash(bytes).Skip(12).ToArray();

11
ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs

@ -70,19 +70,26 @@ namespace ICSharpCode.Decompiler.Metadata @@ -70,19 +70,26 @@ namespace ICSharpCode.Decompiler.Metadata
this.version = version;
}
public DotNetCorePathFinder(string parentAssemblyFileName, string targetFrameworkId, Version version, ReferenceLoadInfo loadInfo = null)
public DotNetCorePathFinder(string parentAssemblyFileName, string targetFrameworkIdString, TargetFrameworkIdentifier targetFramework, Version version, ReferenceLoadInfo loadInfo = null)
{
string assemblyName = Path.GetFileNameWithoutExtension(parentAssemblyFileName);
string basePath = Path.GetDirectoryName(parentAssemblyFileName);
this.version = version;
if (targetFramework == TargetFrameworkIdentifier.NETStandard) {
// .NET Standard 2.1 is implemented by .NET Core 3.0 or higher
if (version.Major == 2 && version.Minor == 1) {
this.version = new Version(3, 0, 0);
}
}
var depsJsonFileName = Path.Combine(basePath, $"{assemblyName}.deps.json");
if (!File.Exists(depsJsonFileName)) {
loadInfo?.AddMessage(assemblyName, MessageKind.Warning, $"{assemblyName}.deps.json could not be found!");
return;
}
packages = LoadPackageInfos(depsJsonFileName, targetFrameworkId).ToArray();
packages = LoadPackageInfos(depsJsonFileName, targetFrameworkIdString).ToArray();
foreach (var path in LookupPaths) {
foreach (var p in packages) {

4
ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

@ -26,7 +26,7 @@ using System.Text; @@ -26,7 +26,7 @@ using System.Text;
namespace ICSharpCode.Decompiler.Metadata
{
enum TargetFrameworkIdentifier
public enum TargetFrameworkIdentifier
{
NETFramework,
NETCoreApp,
@ -183,7 +183,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -183,7 +183,7 @@ namespace ICSharpCode.Decompiler.Metadata
if (IsZeroOrAllOnes(targetFrameworkVersion))
goto default;
if (dotNetCorePathFinder == null) {
dotNetCorePathFinder = new DotNetCorePathFinder(mainAssemblyFileName, targetFramework, targetFrameworkVersion);
dotNetCorePathFinder = new DotNetCorePathFinder(mainAssemblyFileName, targetFramework, targetFrameworkIdentifier, targetFrameworkVersion);
}
file = dotNetCorePathFinder.TryResolveDotNetCore(name);
if (file != null)

26
ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using ICSharpCode.Decompiler.Util;
@ -540,5 +541,30 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -540,5 +541,30 @@ namespace ICSharpCode.Decompiler.TypeSystem
{
return type.ChangeNullability(Nullability.Oblivious);
}
public static bool IsDirectImportOf(this ITypeDefinition type, IModule module)
{
var moduleReference = type.ParentModule;
foreach (var asmRef in module.PEFile.AssemblyReferences) {
if (asmRef.FullName == moduleReference.FullAssemblyName)
return true;
if (asmRef.Name == "netstandard" && asmRef.GetPublicKeyToken() != null) {
var referencedModule = module.Compilation.FindModuleByReference(asmRef);
if (referencedModule != null && !referencedModule.PEFile.GetTypeForwarder(type.FullTypeName).IsNil)
return true;
}
}
return false;
}
public static IModule FindModuleByReference(this ICompilation compilation, IAssemblyReference assemblyName)
{
foreach (var module in compilation.Modules) {
if (module.FullAssemblyName == assemblyName.FullName) {
return module;
}
}
return null;
}
}
}

Loading…
Cancel
Save