Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jbevain@gmail.com>2017-10-25 02:01:55 +0300
committerGitHub <noreply@github.com>2017-10-25 02:01:55 +0300
commit3145301c039bfef6f9bfe0f1526f076b3652a5fc (patch)
treee6af35a886c178ba02a593b3a07acf5e9c367cb2
parent249aa89a318f986d65ef3248cb48ab8a34b79f10 (diff)
parent6a55f42cdfbbe3d16aa1c2832f3a50c74694c8da (diff)
Merge pull request #444 from tmat/NetStandardTests
Include Mono.Cecil.Tests.csproj in netstandard build
-rw-r--r--Mono.Cecil.Tests.props27
-rw-r--r--Mono.Cecil.props11
-rw-r--r--Mono.Cecil.sln20
-rw-r--r--Mono.Cecil/BaseAssemblyResolver.cs58
-rw-r--r--Mono.Cecil/DefaultAssemblyResolver.cs4
-rw-r--r--Mono.Cecil/ModuleDefinition.cs14
-rw-r--r--Mono/Type.cs3
-rw-r--r--NetStandard.props2
-rw-r--r--Test/Mono.Cecil.Tests.csproj27
-rw-r--r--Test/Mono.Cecil.Tests/AssemblyTests.cs6
-rw-r--r--Test/Mono.Cecil.Tests/CallerMemberNameAttribute.cs10
-rw-r--r--Test/Mono.Cecil.Tests/CompilationService.cs110
-rw-r--r--Test/Mono.Cecil.Tests/CustomAttributesTests.cs18
-rw-r--r--Test/Mono.Cecil.Tests/ImageReadTests.cs3
-rw-r--r--Test/Mono.Cecil.Tests/ImportCecilTests.cs20
-rw-r--r--Test/Mono.Cecil.Tests/ImportReflectionTests.cs35
-rw-r--r--Test/Mono.Cecil.Tests/MethodTests.cs2
-rw-r--r--Test/Mono.Cecil.Tests/ModuleTests.cs20
-rw-r--r--Test/Mono.Cecil.Tests/ResolveTests.cs23
-rw-r--r--Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs4
-rw-r--r--Test/Mono.Cecil.Tests/TypeParserTests.cs15
-rw-r--r--Test/Mono.Cecil.Tests/WindowsRuntimeAssemblyResolver.cs5
-rw-r--r--Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs5
23 files changed, 335 insertions, 107 deletions
diff --git a/Mono.Cecil.Tests.props b/Mono.Cecil.Tests.props
index e129090..e4a4031 100644
--- a/Mono.Cecil.Tests.props
+++ b/Mono.Cecil.Tests.props
@@ -2,9 +2,24 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDirectory>$(MSBuildProjectDirectory)</BuildDirectory>
+ <IsTestProject>true</IsTestProject>
</PropertyGroup>
<Import Project="Mono.Cecil.props" />
- <ItemGroup>
+ <PropertyGroup Condition="'$(NetStandard)' == 'true'">
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ </PropertyGroup>
+ <ItemGroup Condition="'$(NetStandard)' == 'true'">
+ <PackageReference Include="NUnit">
+ <Version>3.7.1</Version>
+ </PackageReference>
+ <PackageReference Include="Microsoft.NET.Test.Sdk">
+ <Version>15.3.0</Version>
+ </PackageReference>
+ <PackageReference Include="NUnit3TestAdapter">
+ <Version>3.8.0</Version>
+ </PackageReference>
+ </ItemGroup>
+ <ItemGroup Condition="'$(NetStandard)' != 'true'">
<Reference Include="nunit.core">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildThisFileDirectory)\Test\libs\nunit-2.6.2\nunit.core.dll</HintPath>
@@ -18,4 +33,14 @@
<HintPath>$(MSBuildThisFileDirectory)\Test\libs\nunit-2.6.2\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
+ <!-- Workaround for https://github.com/Microsoft/msbuild/issues/1310 -->
+ <Target Name="ForceGenerationOfBindingRedirects"
+ AfterTargets="ResolveAssemblyReferences"
+ BeforeTargets="GenerateBindingRedirects"
+ Condition="'$(AutoGenerateBindingRedirects)' == 'true'">
+ <PropertyGroup>
+ <!-- Needs to be set in a target because it has to be set after the initial evaluation in the common targets -->
+ <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
+ </PropertyGroup>
+ </Target>
</Project>
diff --git a/Mono.Cecil.props b/Mono.Cecil.props
index da63a2f..366603e 100644
--- a/Mono.Cecil.props
+++ b/Mono.Cecil.props
@@ -36,18 +36,19 @@
</PropertyGroup>
<PropertyGroup Condition=" $(Configuration.StartsWith('net_3_5')) ">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <DefineConstants>$(DefineConstants);</DefineConstants>
+ <DefineConstants>$(DefineConstants);NET_3_5;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" $(Configuration.StartsWith('net_4_0')) ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);NET_4_0;</DefineConstants>
</PropertyGroup>
- <PropertyGroup Condition=" $(NetStandard) ">
- <TargetFramework>netstandard1.3</TargetFramework>
+ <PropertyGroup Condition="'$(NetStandard)' == 'true'">
+ <TargetFramework Condition="'$(IsTestProject)' == 'true'">netcoreapp2.0</TargetFramework>
+ <TargetFramework Condition="'$(IsTestProject)' != 'true'">netstandard1.3</TargetFramework>
</PropertyGroup>
- <Import Project="NetStandard.props" Condition=" $(NetStandard) " />
+ <Import Project="NetStandard.props" Condition="'$(NetStandard)' == 'true'" />
<!-- Shared References -->
- <ItemGroup Condition=" ! $(NetStandard) ">
+ <ItemGroup Condition="'$(NetStandard)' != 'true'">
<Reference Include="System.Core" />
<Reference Include="System" />
</ItemGroup>
diff --git a/Mono.Cecil.sln b/Mono.Cecil.sln
index f7ce9ef..a8c436f 100644
--- a/Mono.Cecil.sln
+++ b/Mono.Cecil.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.26927.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{74E5ECE0-06B4-401C-AEBA-E8DD53E17943}"
EndProject
@@ -22,6 +22,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Rocks.Tests", "r
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Rocks", "rocks\Mono.Cecil.Rocks.csproj", "{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E0893F44-CB9F-49C5-B38C-70082EFC5072}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
net_3_5_Debug_ReadOnly|Any CPU = net_3_5_Debug_ReadOnly|Any CPU
@@ -81,9 +86,11 @@ Global
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
+ {A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug|Any CPU.Build.0 = netstandard_Debug|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
+ {A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release|Any CPU.Build.0 = netstandard_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
@@ -125,10 +132,8 @@ Global
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
- {AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
- {AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
@@ -171,10 +176,8 @@ Global
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
- {29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
- {29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
@@ -193,10 +196,8 @@ Global
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
- {C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
- {C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
@@ -234,4 +235,7 @@ Global
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943}
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943}
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {D75C0801-AFCB-4B1F-90AD-2B7852A74E6A}
+ EndGlobalSection
EndGlobal
diff --git a/Mono.Cecil/BaseAssemblyResolver.cs b/Mono.Cecil/BaseAssemblyResolver.cs
index 14b7cd3..cf6a3a3 100644
--- a/Mono.Cecil/BaseAssemblyResolver.cs
+++ b/Mono.Cecil/BaseAssemblyResolver.cs
@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Reflection;
using System.Text;
using Mono.Collections.Generic;
@@ -65,14 +66,19 @@ namespace Mono.Cecil {
#endif
}
-#if !NET_CORE
public abstract class BaseAssemblyResolver : IAssemblyResolver {
static readonly bool on_mono = Type.GetType ("Mono.Runtime") != null;
readonly Collection<string> directories;
+#if NET_CORE
+ // Maps file names of available trusted platform assemblies to their full paths.
+ // Internal for testing.
+ internal static readonly Lazy<Dictionary<string, string>> TrustedPlatformAssemblies = new Lazy<Dictionary<string, string>> (CreateTrustedPlatformAssemblyMap);
+#else
Collection<string> gac_paths;
+#endif
public void AddSearchDirectory (string directory)
{
@@ -127,6 +133,11 @@ namespace Mono.Cecil {
};
}
+#if NET_CORE
+ assembly = SearchTrustedPlatformAssemblies (name, parameters);
+ if (assembly != null)
+ return assembly;
+#else
var framework_dir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName);
var framework_dirs = on_mono
? new [] { framework_dir, Path.Combine (framework_dir, "Facades") }
@@ -151,7 +162,7 @@ namespace Mono.Cecil {
assembly = SearchDirectory (name, framework_dirs, parameters);
if (assembly != null)
return assembly;
-
+#endif
if (ResolveFailure != null) {
assembly = ResolveFailure (this, name);
if (assembly != null)
@@ -161,6 +172,44 @@ namespace Mono.Cecil {
throw new AssemblyResolutionException (name);
}
+#if NET_CORE
+ AssemblyDefinition SearchTrustedPlatformAssemblies (AssemblyNameReference name, ReaderParameters parameters)
+ {
+ if (name.IsWindowsRuntime)
+ return null;
+
+ if (TrustedPlatformAssemblies.Value.TryGetValue (name.Name, out string path))
+ return GetAssembly (path, parameters);
+
+ return null;
+ }
+
+ static Dictionary<string, string> CreateTrustedPlatformAssemblyMap ()
+ {
+ var result = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
+
+ string paths;
+
+ try {
+ // AppContext is only available on platforms that implement .NET Standard 1.6
+ var appContextType = Type.GetType ("System.AppContext, System.AppContext, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
+ var getData = appContextType?.GetTypeInfo ().GetDeclaredMethod ("GetData");
+ paths = (string) getData?.Invoke (null, new [] { "TRUSTED_PLATFORM_ASSEMBLIES" });
+ } catch {
+ paths = null;
+ }
+
+ if (paths == null)
+ return result;
+
+ foreach (var path in paths.Split (Path.PathSeparator))
+ if (string.Equals (Path.GetExtension (path), ".dll", StringComparison.OrdinalIgnoreCase))
+ result [Path.GetFileNameWithoutExtension (path)] = path;
+
+ return result;
+ }
+#endif
+
protected virtual AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
{
var extensions = name.IsWindowsRuntime ? new [] { ".winmd", ".dll" } : new [] { ".exe", ".dll" };
@@ -185,11 +234,11 @@ namespace Mono.Cecil {
return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0;
}
+#if !NET_CORE
AssemblyDefinition GetCorlib (AssemblyNameReference reference, ReaderParameters parameters)
{
var version = reference.Version;
var corlib = typeof (object).Assembly.GetName ();
-
if (corlib.Version == version || IsZero (version))
return GetAssembly (typeof (object).Module.FullyQualifiedName, parameters);
@@ -325,7 +374,7 @@ namespace Mono.Cecil {
return null;
}
-
+#endif
static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
var gac_folder = new StringBuilder ()
@@ -352,5 +401,4 @@ namespace Mono.Cecil {
{
}
}
-#endif
}
diff --git a/Mono.Cecil/DefaultAssemblyResolver.cs b/Mono.Cecil/DefaultAssemblyResolver.cs
index 197aaa0..755071e 100644
--- a/Mono.Cecil/DefaultAssemblyResolver.cs
+++ b/Mono.Cecil/DefaultAssemblyResolver.cs
@@ -8,8 +8,6 @@
// Licensed under the MIT/X11 license.
//
-#if !NET_CORE
-
using System;
using System.Collections.Generic;
@@ -61,5 +59,3 @@ namespace Mono.Cecil {
}
}
}
-
-#endif
diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs
index d986d16..1fdfb84 100644
--- a/Mono.Cecil/ModuleDefinition.cs
+++ b/Mono.Cecil/ModuleDefinition.cs
@@ -389,13 +389,11 @@ namespace Mono.Cecil {
public IAssemblyResolver AssemblyResolver {
get {
-#if !NET_CORE
if (assembly_resolver.value == null) {
lock (module_lock) {
assembly_resolver = Disposable.Owned (new DefaultAssemblyResolver () as IAssemblyResolver);
}
}
-#endif
return assembly_resolver.value;
}
@@ -725,28 +723,16 @@ namespace Mono.Cecil {
internal FieldDefinition Resolve (FieldReference field)
{
-#if NET_CORE
- if (MetadataResolver == null)
- throw new NotSupportedException ();
-#endif
return MetadataResolver.Resolve (field);
}
internal MethodDefinition Resolve (MethodReference method)
{
-#if NET_CORE
- if (MetadataResolver == null)
- throw new NotSupportedException ();
-#endif
return MetadataResolver.Resolve (method);
}
internal TypeDefinition Resolve (TypeReference type)
{
-#if NET_CORE
- if (MetadataResolver == null)
- throw new NotSupportedException ();
-#endif
return MetadataResolver.Resolve (type);
}
diff --git a/Mono/Type.cs b/Mono/Type.cs
index 4ff2048..fd53f81 100644
--- a/Mono/Type.cs
+++ b/Mono/Type.cs
@@ -100,7 +100,8 @@ namespace Mono {
public static Type [] GetGenericArguments (this Type type)
{
#if NET_CORE
- return type.GetTypeInfo ().GenericTypeArguments;
+ var info = type.GetTypeInfo ();
+ return info.IsGenericTypeDefinition ? info.GenericTypeParameters : info.GenericTypeArguments;
#else
return type.GetGenericArguments ();
#endif
diff --git a/NetStandard.props b/NetStandard.props
index d5f4196..bc0bacc 100644
--- a/NetStandard.props
+++ b/NetStandard.props
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <DefineConstants>$(DefineConstants);NET_4_0;NET_CORE;</DefineConstants>
+ <DefineConstants>$(DefineConstants);NET_CORE;</DefineConstants>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
diff --git a/Test/Mono.Cecil.Tests.csproj b/Test/Mono.Cecil.Tests.csproj
index 9277d6a..a8c4d0e 100644
--- a/Test/Mono.Cecil.Tests.csproj
+++ b/Test/Mono.Cecil.Tests.csproj
@@ -1,10 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="..\Mono.Cecil.Tests.props" />
<PropertyGroup>
<ProjectGuid>{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}</ProjectGuid>
<RootNamespace>Mono.Cecil.Tests</RootNamespace>
<AssemblyName>Mono.Cecil.Tests</AssemblyName>
</PropertyGroup>
+ <ItemGroup Condition="'$(NetStandard)' == 'true'">
+ <PackageReference Include="System.Reflection.TypeExtensions">
+ <Version>4.3.0</Version>
+ </PackageReference>
+ <PackageReference Include="System.Diagnostics.Process">
+ <Version>4.3.0</Version>
+ </PackageReference>
+ <PackageReference Include="System.Diagnostics.StackTrace">
+ <Version>4.3.0</Version>
+ </PackageReference>
+ <PackageReference Include="System.Diagnostics.FileVersionInfo">
+ <Version>4.3.0</Version>
+ </PackageReference>
+ <PackageReference Include="System.Runtime.Loader">
+ <Version>4.3.0</Version>
+ </PackageReference>
+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp">
+ <Version>2.3.2</Version>
+ </PackageReference>
+ <PackageReference Include="Microsoft.CodeAnalysis.VisualBasic">
+ <Version>2.3.2</Version>
+ </PackageReference>
+ </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
@@ -26,6 +50,5 @@
<ItemGroup>
<None Include="Resources\**\*" />
</ItemGroup>
- <Import Project="..\Mono.Cecil.Tests.props" />
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition="'$(NetStandard)' != 'true'" />
</Project> \ No newline at end of file
diff --git a/Test/Mono.Cecil.Tests/AssemblyTests.cs b/Test/Mono.Cecil.Tests/AssemblyTests.cs
index 0d484de..af45a3c 100644
--- a/Test/Mono.Cecil.Tests/AssemblyTests.cs
+++ b/Test/Mono.Cecil.Tests/AssemblyTests.cs
@@ -59,6 +59,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void Retargetable ()
{
+ if (Platform.OnCoreClr)
+ return;
+
TestModule ("RetargetableExample.dll", module => {
var type = module.Types [1];
var property = type.Properties [0];
@@ -76,6 +79,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void SystemRuntime ()
{
+ if (Platform.OnCoreClr)
+ return;
+
TestModule ("System.Runtime.dll", module => {
Assert.AreEqual ("System.Runtime", module.Assembly.Name.Name);
Assert.AreEqual (1, module.AssemblyReferences.Count);
diff --git a/Test/Mono.Cecil.Tests/CallerMemberNameAttribute.cs b/Test/Mono.Cecil.Tests/CallerMemberNameAttribute.cs
new file mode 100644
index 0000000..63bd9b8
--- /dev/null
+++ b/Test/Mono.Cecil.Tests/CallerMemberNameAttribute.cs
@@ -0,0 +1,10 @@
+#if NET_3_5 || NET_4_0
+namespace System.Runtime.CompilerServices {
+ [AttributeUsage (AttributeTargets.Parameter, Inherited = false)]
+ public sealed class CallerMemberNameAttribute : Attribute {
+ public CallerMemberNameAttribute ()
+ {
+ }
+ }
+}
+#endif \ No newline at end of file
diff --git a/Test/Mono.Cecil.Tests/CompilationService.cs b/Test/Mono.Cecil.Tests/CompilationService.cs
index 877ed24..5501d57 100644
--- a/Test/Mono.Cecil.Tests/CompilationService.cs
+++ b/Test/Mono.Cecil.Tests/CompilationService.cs
@@ -4,9 +4,16 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
-
+using System.Reflection;
using NUnit.Framework;
+#if NET_CORE
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Emit;
+using CS = Microsoft.CodeAnalysis.CSharp;
+using VB = Microsoft.CodeAnalysis.VisualBasic;
+#endif
+
namespace Mono.Cecil.Tests {
struct CompilationResult {
@@ -22,7 +29,23 @@ namespace Mono.Cecil.Tests {
public static class Platform {
- public static bool OnMono { get { return typeof (object).Assembly.GetType ("Mono.Runtime") != null; } }
+ public static bool OnMono {
+ get { return TryGetType ("Mono.Runtime") != null; }
+ }
+
+ public static bool OnCoreClr {
+ get { return TryGetType ("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") != null; }
+ }
+
+ static Type TryGetType (string assemblyQualifiedName)
+ {
+ try {
+ // Note that throwOnError=false only suppresses some exceptions, not all.
+ return Type.GetType(assemblyQualifiedName, throwOnError: false);
+ } catch {
+ return null;
+ }
+ }
}
abstract class CompilationService {
@@ -68,8 +91,11 @@ namespace Mono.Cecil.Tests {
return IlasmCompilationService.Instance.Compile (name);
if (extension == ".cs" || extension == ".vb")
+#if NET_CORE
+ return RoslynCompilationService.Instance.Compile (name);
+#else
return CodeDomCompilationService.Instance.Compile (name);
-
+#endif
throw new NotSupportedException (extension);
}
@@ -84,9 +110,11 @@ namespace Mono.Cecil.Tests {
public static void Verify (string name)
{
+#if !NET_CORE
var output = Platform.OnMono ? ShellService.PEDump (name) : ShellService.PEVerify (name);
if (output.ExitCode != 0)
Assert.Fail (output.ToString ());
+#endif
}
}
@@ -112,6 +140,76 @@ namespace Mono.Cecil.Tests {
}
}
+#if NET_CORE
+
+ class RoslynCompilationService : CompilationService {
+
+ public static readonly RoslynCompilationService Instance = new RoslynCompilationService ();
+
+ protected override string CompileFile (string name)
+ {
+ var compilation = GetCompilation (name);
+ var outputName = GetCompiledFilePath (name);
+
+ var result = compilation.Emit (outputName);
+ Assert.IsTrue (result.Success, GetErrorMessage (result));
+
+ return outputName;
+ }
+
+ static Compilation GetCompilation (string name)
+ {
+ var assemblyName = Path.GetFileNameWithoutExtension (name);
+ var source = File.ReadAllText (name);
+
+ var tpa = BaseAssemblyResolver.TrustedPlatformAssemblies.Value;
+
+ var references = new []
+ {
+ MetadataReference.CreateFromFile (tpa ["netstandard"]),
+ MetadataReference.CreateFromFile (tpa ["mscorlib"]),
+ MetadataReference.CreateFromFile (tpa ["System.Private.CoreLib"]),
+ MetadataReference.CreateFromFile (tpa ["System.Runtime"]),
+ MetadataReference.CreateFromFile (tpa ["System.Console"]),
+ MetadataReference.CreateFromFile (tpa ["System.Security.AccessControl"]),
+ };
+
+ var extension = Path.GetExtension (name);
+ switch (extension) {
+ case ".cs":
+ return CS.CSharpCompilation.Create (
+ assemblyName,
+ new [] { CS.SyntaxFactory.ParseSyntaxTree (source) },
+ references,
+ new CS.CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
+
+ case ".vb":
+ return VB.VisualBasicCompilation.Create (
+ assemblyName,
+ new [] { VB.SyntaxFactory.ParseSyntaxTree (source) },
+ references,
+ new VB.VisualBasicCompilationOptions (OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
+
+ default:
+ throw new NotSupportedException ();
+ }
+ }
+
+ static string GetErrorMessage (EmitResult result)
+ {
+ if (result.Success)
+ return string.Empty;
+
+ var builder = new StringBuilder ();
+ foreach (var diagnostic in result.Diagnostics)
+ builder.AppendLine (diagnostic.ToString ());
+
+ return builder.ToString ();
+ }
+ }
+
+#else
+
class CodeDomCompilationService : CompilationService {
public static readonly CodeDomCompilationService Instance = new CodeDomCompilationService ();
@@ -166,6 +264,8 @@ namespace Mono.Cecil.Tests {
}
}
+#endif
+
class ShellService {
public class ProcessOutput {
@@ -243,9 +343,13 @@ namespace Mono.Cecil.Tests {
static string NetFrameworkTool (string tool)
{
+#if NET_CORE
+ return Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Windows), "Microsoft.NET", "Framework", "v4.0.30319", tool + ".exe");
+#else
return Path.Combine (
Path.GetDirectoryName (typeof (object).Assembly.Location),
tool + ".exe");
+#endif
}
static string WinSdkTool (string tool)
diff --git a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
index a89fcfd..8ec0270 100644
--- a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
+++ b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
@@ -21,15 +21,15 @@ namespace Mono.Cecil.Tests {
TestCSharp ("CustomAttributes.cs", module => {
var hamster = module.GetType ("Hamster");
- Assert.IsTrue (hamster.HasCustomAttributes);
- Assert.AreEqual (1, hamster.CustomAttributes.Count);
+ Assert.IsTrue (hamster.HasCustomAttributes);
+ Assert.AreEqual (1, hamster.CustomAttributes.Count);
- var attribute = hamster.CustomAttributes [0];
- Assert.AreEqual ("System.Void FooAttribute::.ctor(System.String)",
- attribute.Constructor.FullName);
+ var attribute = hamster.CustomAttributes [0];
+ Assert.AreEqual ("System.Void FooAttribute::.ctor(System.String)",
+ attribute.Constructor.FullName);
- Assert.IsTrue (attribute.HasConstructorArguments);
- Assert.AreEqual (1, attribute.ConstructorArguments.Count);
+ Assert.IsTrue (attribute.HasConstructorArguments);
+ Assert.AreEqual (1, attribute.ConstructorArguments.Count);
AssertArgument ("bar", attribute.ConstructorArguments [0]);
});
@@ -559,10 +559,10 @@ namespace Mono.Cecil.Tests {
}
switch (Type.GetTypeCode (value.GetType ())) {
- case TypeCode.String:
+ case System.TypeCode.String:
signature.AppendFormat ("\"{0}\"", value);
break;
- case TypeCode.Char:
+ case System.TypeCode.Char:
signature.AppendFormat ("'{0}'", (char) value);
break;
default:
diff --git a/Test/Mono.Cecil.Tests/ImageReadTests.cs b/Test/Mono.Cecil.Tests/ImageReadTests.cs
index 16f89d2..16b8a7b 100644
--- a/Test/Mono.Cecil.Tests/ImageReadTests.cs
+++ b/Test/Mono.Cecil.Tests/ImageReadTests.cs
@@ -170,6 +170,7 @@ namespace Mono.Cecil.Tests {
}, verify: false);
}
+#if !NET_CORE
[Test]
public void WindowsRuntimeComponentAssembly ()
{
@@ -181,7 +182,7 @@ namespace Mono.Cecil.Tests {
Assert.IsTrue (module.Assembly.Name.IsWindowsRuntime);
}, verify: false, assemblyResolver: resolver);
}
-
+#endif
[Test]
public void DeterministicAssembly ()
{
diff --git a/Test/Mono.Cecil.Tests/ImportCecilTests.cs b/Test/Mono.Cecil.Tests/ImportCecilTests.cs
index a28b093..bc12f5e 100644
--- a/Test/Mono.Cecil.Tests/ImportCecilTests.cs
+++ b/Test/Mono.Cecil.Tests/ImportCecilTests.cs
@@ -1,7 +1,6 @@
#if !READ_ONLY
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.Linq;
using SR = System.Reflection;
@@ -255,6 +254,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ContextGenericTest ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var module = ModuleDefinition.ReadModule (typeof (ContextGeneric1Method2<>).Module.FullyQualifiedName);
// by mixing open generics with 2 & 1 parameters, we make sure the right context is used (because otherwise, an exception will be thrown)
var type = typeof (ContextGeneric1Method2<>).MakeGenericType (typeof (ContextGeneric2Method1<,>));
@@ -287,11 +289,10 @@ namespace Mono.Cecil.Tests {
delegate void Emitter (ModuleDefinition module, MethodBody body);
- [MethodImpl (MethodImplOptions.NoInlining)]
- static TDelegate Compile<TDelegate> (Emitter emitter)
+ static TDelegate Compile<TDelegate> (Emitter emitter, [CallerMemberName] string testMethodName = null)
where TDelegate : class
{
- var name = GetTestCaseName ();
+ var name = "ImportCecil_" + testMethodName;
var module = CreateTestModule<TDelegate> (name, emitter);
var assembly = LoadTestModule (module);
@@ -362,15 +363,6 @@ namespace Mono.Cecil.Tests {
{
return ModuleDefinition.CreateModule (name, ModuleKind.Dll);
}
-
- [MethodImpl (MethodImplOptions.NoInlining)]
- static string GetTestCaseName ()
- {
- var stack_trace = new StackTrace ();
- var stack_frame = stack_trace.GetFrame (2);
-
- return "ImportCecil_" + stack_frame.GetMethod ().Name;
- }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
index 0476861..c99ca4f 100644
--- a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
+++ b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
@@ -1,7 +1,6 @@
#if !READ_ONLY
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using SR = System.Reflection;
using System.Runtime.CompilerServices;
@@ -156,6 +155,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericField ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var get_field = Compile<Func<Generic<string>, string>> ((module, body) => {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -173,6 +175,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericMethod ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var generic_identity = Compile<Func<Generic<int>, int, int>> ((module, body) => {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -187,6 +192,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericMethodSpec ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -202,6 +210,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportComplexGenericMethodSpec ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -279,6 +290,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericFieldFromContext ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var list_foo = typeof (Foo<>).GetField ("list").FieldType;
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo);
var generic_list_foo_open_field = generic_list_foo_open.GetField ("Field");
@@ -295,6 +309,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericMethodFromContext ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var list_foo = typeof (Foo<>).GetField ("list").FieldType;
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo);
var generic_list_foo_open_method = generic_list_foo_open.GetMethod ("Method");
@@ -334,11 +351,10 @@ namespace Mono.Cecil.Tests {
delegate void Emitter (ModuleDefinition module, MethodBody body);
- [MethodImpl (MethodImplOptions.NoInlining)]
- static TDelegate Compile<TDelegate> (Emitter emitter)
+ static TDelegate Compile<TDelegate> (Emitter emitter, [CallerMemberName] string testMethodName = null)
where TDelegate : class
{
- var name = GetTestCaseName ();
+ var name = "ImportReflection_" + testMethodName;
var module = CreateTestModule<TDelegate> (name, emitter);
var assembly = LoadTestModule (module);
@@ -409,15 +425,6 @@ namespace Mono.Cecil.Tests {
{
return ModuleDefinition.CreateModule (name, ModuleKind.Dll);
}
-
- [MethodImpl (MethodImplOptions.NoInlining)]
- static string GetTestCaseName ()
- {
- var stack_trace = new StackTrace ();
- var stack_frame = stack_trace.GetFrame (2);
-
- return "ImportReflection_" + stack_frame.GetMethod ().Name;
- }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/Test/Mono.Cecil.Tests/MethodTests.cs b/Test/Mono.Cecil.Tests/MethodTests.cs
index bbf1742..b878613 100644
--- a/Test/Mono.Cecil.Tests/MethodTests.cs
+++ b/Test/Mono.Cecil.Tests/MethodTests.cs
@@ -204,6 +204,8 @@ namespace Mono.Cecil.Tests {
var beta = type.GetMethod ("Beta");
var charlie = type.GetMethod ("Charlie");
+ // Note that the test depends on the C# compiler emitting the constructor call instruction as
+ // the first instruction of the method body. This requires optimizations to be enabled.
var new_list_beta = (MethodReference) beta.Body.Instructions [0].Operand;
var new_list_charlie = (MethodReference) charlie.Body.Instructions [0].Operand;
diff --git a/Test/Mono.Cecil.Tests/ModuleTests.cs b/Test/Mono.Cecil.Tests/ModuleTests.cs
index 476b8ff..2b8eda1 100644
--- a/Test/Mono.Cecil.Tests/ModuleTests.cs
+++ b/Test/Mono.Cecil.Tests/ModuleTests.cs
@@ -49,7 +49,10 @@ namespace Mono.Cecil.Tests {
[Test]
public void MultiModules ()
{
- TestModule ("mma.exe", module => {
+ if (Platform.OnCoreClr)
+ return;
+
+ TestModule("mma.exe", module => {
var assembly = module.Assembly;
Assert.AreEqual (3, assembly.Modules.Count);
@@ -157,6 +160,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void ExportedTypeFromNetModule ()
{
+ if (Platform.OnCoreClr)
+ return;
+
TestModule ("mma.exe", module => {
Assert.IsTrue (module.HasExportedTypes);
Assert.AreEqual (2, module.ExportedTypes.Count);
@@ -183,14 +189,14 @@ namespace Mono.Cecil.Tests {
var exported_type = module.ExportedTypes [0];
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute", exported_type.FullName);
- Assert.AreEqual ("mscorlib", exported_type.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", exported_type.Scope.Name);
Assert.IsTrue (exported_type.IsForwarder);
var nested_exported_type = module.ExportedTypes [1];
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute/DebuggingModes", nested_exported_type.FullName);
Assert.AreEqual (exported_type, nested_exported_type.DeclaringType);
- Assert.AreEqual ("mscorlib", nested_exported_type.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", nested_exported_type.Scope.Name);
});
}
@@ -199,7 +205,7 @@ namespace Mono.Cecil.Tests {
{
TestCSharp ("CustomAttributes.cs", module => {
Assert.IsTrue (module.HasTypeReference ("System.Attribute"));
- Assert.IsTrue (module.HasTypeReference ("mscorlib", "System.Attribute"));
+ Assert.IsTrue (module.HasTypeReference (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", "System.Attribute"));
Assert.IsFalse (module.HasTypeReference ("System.Core", "System.Attribute"));
Assert.IsFalse (module.HasTypeReference ("System.Linq.Enumerable"));
@@ -234,10 +240,9 @@ namespace Mono.Cecil.Tests {
}
[Test]
- [ExpectedException (typeof (BadImageFormatException))]
public void OpenIrrelevantFile ()
{
- GetResourceModule ("text_file.txt");
+ Assert.Throws<BadImageFormatException> (() => GetResourceModule ("text_file.txt"));
}
[Test]
@@ -273,7 +278,8 @@ namespace Mono.Cecil.Tests {
{
using (var module = ModuleDefinition.ReadModule (file))
{
- Assert.IsNotNullOrEmpty (module.FileName);
+ Assert.IsNotNull (module.FileName);
+ Assert.IsNotEmpty (module.FileName);
Assert.AreEqual (path, module.FileName);
}
}
diff --git a/Test/Mono.Cecil.Tests/ResolveTests.cs b/Test/Mono.Cecil.Tests/ResolveTests.cs
index aab7d0c..ec579b5 100644
--- a/Test/Mono.Cecil.Tests/ResolveTests.cs
+++ b/Test/Mono.Cecil.Tests/ResolveTests.cs
@@ -26,7 +26,8 @@ namespace Mono.Cecil.Tests {
Assert.IsNotNull (definition);
Assert.AreEqual ("System.String System.String::Empty", definition.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib",
+ definition.Module.Assembly.Name.Name);
}
delegate string GetSubstring (string str, int start, int length);
@@ -42,7 +43,8 @@ namespace Mono.Cecil.Tests {
Assert.IsNotNull (definition);
Assert.AreEqual ("System.String System.String::Substring(System.Int32,System.Int32)", definition.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib",
+ definition.Module.Assembly.Name.Name);
}
[Test]
@@ -56,7 +58,8 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("get_Length", definition.Name);
Assert.AreEqual ("System.String", definition.DeclaringType.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib",
+ definition.Module.Assembly.Name.Name);
}
[Test]
@@ -72,7 +75,8 @@ namespace Mono.Cecil.Tests {
Assert.IsNotNull (definition);
Assert.AreEqual ("System.Void System.Collections.Generic.List`1::Add(T)", definition.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib",
+ definition.Module.Assembly.Name.Name);
}
[Test]
@@ -92,7 +96,8 @@ namespace Mono.Cecil.Tests {
Assert.IsNotNull (definition);
Assert.AreEqual ("System.Boolean System.Collections.Generic.Dictionary`2::TryGetValue(TKey,TValue&)", definition.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib",
+ definition.Module.Assembly.Name.Name);
}
class CustomResolver : DefaultAssemblyResolver {
@@ -140,7 +145,7 @@ namespace Mono.Cecil.Tests {
var definition = reference.Resolve ();
Assert.IsNotNull (definition);
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute", definition.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", definition.Module.Assembly.Name.Name);
}
[Test]
@@ -162,7 +167,7 @@ namespace Mono.Cecil.Tests {
var definition = reference.Resolve ();
Assert.IsNotNull (definition);
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute/DebuggingModes", definition.FullName);
- Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", definition.Module.Assembly.Name.Name);
}
[Test]
@@ -223,7 +228,9 @@ namespace Mono.Cecil.Tests {
Assert.IsTrue (reference.IsRetargetable);
var assembly = resolver.Resolve (reference);
Assert.IsNotNull (assembly);
- Assert.AreEqual (typeof (object).Assembly.GetName ().Version, assembly.Name.Version);
+
+ if (!Platform.OnCoreClr)
+ Assert.AreEqual (typeof (object).Assembly.GetName ().Version, assembly.Name.Version);
}
}
diff --git a/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs b/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs
index 3b59e6f..c3106f4 100644
--- a/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs
+++ b/Test/Mono.Cecil.Tests/SecurityDeclarationTests.cs
@@ -249,10 +249,10 @@ namespace Mono.Cecil.Tests {
}
switch (Type.GetTypeCode (value.GetType ())) {
- case TypeCode.String:
+ case System.TypeCode.String:
signature.AppendFormat ("\"{0}\"", value);
break;
- case TypeCode.Char:
+ case System.TypeCode.Char:
signature.AppendFormat ("'{0}'", (char) value);
break;
default:
diff --git a/Test/Mono.Cecil.Tests/TypeParserTests.cs b/Test/Mono.Cecil.Tests/TypeParserTests.cs
index 603b7f4..a838c07 100644
--- a/Test/Mono.Cecil.Tests/TypeParserTests.cs
+++ b/Test/Mono.Cecil.Tests/TypeParserTests.cs
@@ -233,6 +233,9 @@ namespace Mono.Cecil.Tests {
[Test]
public void GenericInstanceExternArguments ()
{
+ if (Platform.OnCoreClr)
+ return;
+
var module = GetCurrentModule ();
var fullname = string.Format ("System.Collections.Generic.Dictionary`2[[System.Int32, {0}],[System.String, {0}]]",
@@ -280,7 +283,7 @@ namespace Mono.Cecil.Tests {
var instance = type as GenericInstanceType;
Assert.IsNotNull (instance);
Assert.AreEqual (2, instance.GenericArguments.Count);
- Assert.AreEqual ("mscorlib", type.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Runtime" : "mscorlib", type.Scope.Name);
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("System.Collections.Generic", type.Namespace);
Assert.AreEqual ("Dictionary`2", type.Name);
@@ -296,7 +299,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("TypeParserTests", argument.Name);
argument = instance.GenericArguments [1];
- Assert.AreEqual ("mscorlib", argument.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", argument.Scope.Name);
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("System", argument.Namespace);
Assert.AreEqual ("String", argument.Name);
@@ -319,7 +322,7 @@ namespace Mono.Cecil.Tests {
var instance = type as GenericInstanceType;
Assert.IsNotNull (instance);
Assert.AreEqual (2, instance.GenericArguments.Count);
- Assert.AreEqual ("mscorlib", type.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", type.Scope.Name);
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("System.Collections.Generic", type.Namespace);
Assert.AreEqual ("Dictionary`2", type.Name);
@@ -354,7 +357,7 @@ namespace Mono.Cecil.Tests {
var instance = type as GenericInstanceType;
Assert.IsNotNull (instance);
Assert.AreEqual (2, instance.GenericArguments.Count);
- Assert.AreEqual ("mscorlib", type.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Runtime" : "mscorlib", type.Scope.Name);
Assert.AreEqual (module, type.Module);
Assert.AreEqual ("System.Collections.Generic", type.Namespace);
Assert.AreEqual ("Dictionary`2", type.Name);
@@ -364,7 +367,7 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (2, type.GenericParameters.Count);
var argument = instance.GenericArguments [0];
- Assert.AreEqual ("mscorlib", argument.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", argument.Scope.Name);
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("System", argument.Namespace);
Assert.AreEqual ("String", argument.Name);
@@ -385,7 +388,7 @@ namespace Mono.Cecil.Tests {
Assert.IsInstanceOf (typeof (TypeDefinition), argument);
argument = instance.GenericArguments [1];
- Assert.AreEqual ("mscorlib", argument.Scope.Name);
+ Assert.AreEqual (Platform.OnCoreClr ? "System.Private.CoreLib" : "mscorlib", argument.Scope.Name);
Assert.AreEqual (module, argument.Module);
Assert.AreEqual ("System", argument.Namespace);
Assert.AreEqual ("Int32", argument.Name);
diff --git a/Test/Mono.Cecil.Tests/WindowsRuntimeAssemblyResolver.cs b/Test/Mono.Cecil.Tests/WindowsRuntimeAssemblyResolver.cs
index 1e3a90b..fb39e33 100644
--- a/Test/Mono.Cecil.Tests/WindowsRuntimeAssemblyResolver.cs
+++ b/Test/Mono.Cecil.Tests/WindowsRuntimeAssemblyResolver.cs
@@ -1,4 +1,6 @@
-using System;
+#if !NET_CORE
+
+using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Win32;
@@ -91,3 +93,4 @@ namespace Mono.Cecil.Tests {
}
}
}
+#endif \ No newline at end of file
diff --git a/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs b/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs
index 166f4d9..d5ed3b0 100644
--- a/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs
+++ b/Test/Mono.Cecil.Tests/WindowsRuntimeProjectionsTests.cs
@@ -1,4 +1,6 @@
-using NUnit.Framework;
+#if !NET_CORE
+
+using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
@@ -141,3 +143,4 @@ namespace Mono.Cecil.Tests {
protected override string [] CustomListTypeNames { get { return new [] { "CustomList" }; } }
}
}
+#endif