You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
73
external/corefx/src/System.Reflection/System.Reflection.sln
vendored
Normal file
73
external/corefx/src/System.Reflection/System.Reflection.sln
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||

|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Tests.TestExe", "tests\TestExe\System.Reflection.Tests.TestExe.csproj", "{8C19B991-41E9-4B38-9602-E19375397F1D}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{} = {}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.CoreCLR.Tests", "tests\CoreCLR\System.Reflection.CoreCLR.Tests.csproj", "{C8049356-559D-4F34-AC17-56F3AE62C897}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{} = {}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Tests", "tests\System.Reflection.Tests.csproj", "{B027C72E-F04E-42E0-A7F7-993AEF8400D2}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{} = {}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection", "ref\System.Reflection.csproj", "{446DE6F0-47A0-4C2F-A918-768A76CCF461}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
|
||||
DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
|
||||
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{B027C72E-F04E-42E0-A7F7-993AEF8400D2}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{C8049356-559D-4F34-AC17-56F3AE62C897}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{8C19B991-41E9-4B38-9602-E19375397F1D}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
8
external/corefx/src/System.Reflection/dir.props
vendored
Normal file
8
external/corefx/src/System.Reflection/dir.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.2.0.0</AssemblyVersion>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
</PropertyGroup>
|
||||
</Project>
|
9
external/corefx/src/System.Reflection/ref/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Reflection/ref/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netcoreapp;
|
||||
uap;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
17
external/corefx/src/System.Reflection/ref/System.Reflection.Manual.cs
vendored
Normal file
17
external/corefx/src/System.Reflection/ref/System.Reflection.Manual.cs
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// This is only needed for COMAwareEventInfo to inherit from EventInfo. Next version when
|
||||
// Reflection is extensible then we should remove this InternalsVisibleTo.
|
||||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Runtime.InteropServices, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
|
||||
|
||||
// This is required so that AssemblyBuilder can derive from Assembly.
|
||||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Reflection.Emit, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
|
||||
|
||||
// This is required so that DynamicMethod can derive from MethodInfo.
|
||||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Reflection.Emit.Lightweight, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
|
42
external/corefx/src/System.Reflection/ref/System.Reflection.cs
vendored
Normal file
42
external/corefx/src/System.Reflection/ref/System.Reflection.cs
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
// These types were moved down to System.Runtime
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.AmbiguousMatchException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.Assembly))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.AssemblyContentType))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.AssemblyName))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.BindingFlags))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ConstructorInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.CustomAttributeData))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.CustomAttributeNamedArgument))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.CustomAttributeTypedArgument))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.EventInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.FieldInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ICustomAttributeProvider))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.IntrospectionExtensions))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.InvalidFilterCriteriaException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.IReflectableType))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.LocalVariableInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ManifestResourceInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.MemberFilter))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.MemberInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.MemberTypes))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.MethodBase))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.MethodInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.Module))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ParameterInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ParameterModifier))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.PropertyInfo))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ReflectionContext))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ReflectionTypeLoadException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.ResourceLocation))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.TargetException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.TargetInvocationException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.TargetParameterCountException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.TypeFilter))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reflection.TypeInfo))]
|
16
external/corefx/src/System.Reflection/ref/System.Reflection.csproj
vendored
Normal file
16
external/corefx/src/System.Reflection/ref/System.Reflection.csproj
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System.Reflection.cs" />
|
||||
<Compile Include="System.Reflection.Manual.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
10
external/corefx/src/System.Reflection/src/Configurations.props
vendored
Normal file
10
external/corefx/src/System.Reflection/src/Configurations.props
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
net461-Windows_NT;
|
||||
uap101aot-Windows_NT;
|
||||
netcoreapp;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
23
external/corefx/src/System.Reflection/src/System.Reflection.csproj
vendored
Normal file
23
external/corefx/src/System.Reflection/src/System.Reflection.csproj
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyName>System.Reflection</AssemblyName>
|
||||
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
|
||||
</PropertyGroup>
|
||||
<!-- Help VS understand available configurations -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net461-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net461-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap101aot-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap101aot-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<TargetingPackReference Include="mscorlib" Condition="'$(TargetGroup)' == 'net461'" />
|
||||
<TargetingPackReference Include="System.Private.CoreLib" Condition="'$(TargetGroup)' != 'net461'" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ReferenceFromRuntime Include="System.Private.CoreLib" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
353
external/corefx/src/System.Reflection/tests/AssemblyNameTests.cs
vendored
Normal file
353
external/corefx/src/System.Reflection/tests/AssemblyNameTests.cs
vendored
Normal file
@@ -0,0 +1,353 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class AssemblyNameTests
|
||||
{
|
||||
private const ProcessorArchitecture CurrentMaxValue = ProcessorArchitecture.Arm;
|
||||
|
||||
private static IEnumerable<ProcessorArchitecture> ValidProcessorArchitectureValues()
|
||||
{
|
||||
return (ProcessorArchitecture[])Enum.GetValues(typeof(ProcessorArchitecture));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ProcessorArchitectures_TestData()
|
||||
{
|
||||
return ValidProcessorArchitectureValues().Select(arch => new object[] { arch });
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Names_TestData()
|
||||
{
|
||||
yield return new object[] { "name", "name" };
|
||||
yield return new object[] { "NAME", "NAME" };
|
||||
yield return new object[] { "name with spaces", "name with spaces" };
|
||||
yield return new object[] { "\uD800\uDC00", "\uD800\uDC00" };
|
||||
yield return new object[] { "привет", "привет" };
|
||||
|
||||
// Invalid Unicode
|
||||
yield return new object[] { "\uD800", "\uFFFD" };
|
||||
yield return new object[] { "\uDC00", "\uFFFD" };
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_Empty()
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName();
|
||||
Assert.Null(assemblyName.Name);
|
||||
Assert.Equal(ProcessorArchitecture.None, assemblyName.ProcessorArchitecture);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Names_TestData))]
|
||||
public void Ctor_String(string name, string expectedName)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName(name);
|
||||
Assert.Equal(expectedName, assemblyName.Name);
|
||||
Assert.Equal(ProcessorArchitecture.None, assemblyName.ProcessorArchitecture);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, typeof(ArgumentNullException))]
|
||||
[InlineData("", typeof(ArgumentException))]
|
||||
[InlineData("\0", typeof(ArgumentException))]
|
||||
[InlineData("\0a", typeof(ArgumentException))]
|
||||
[InlineData("/a", typeof(FileLoadException))]
|
||||
[InlineData(" ", typeof(FileLoadException))]
|
||||
[InlineData(" \t \r \n ", typeof(FileLoadException))]
|
||||
public void Ctor_String_Invalid(string assemblyName, Type exceptionType)
|
||||
{
|
||||
Assert.Throws(exceptionType, () => new AssemblyName(assemblyName));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Ctor_ProcessorArchitecture_TestData()
|
||||
{
|
||||
// Note that "None" is not valid as part of the name. To get it, the ProcessorArchitecture must be omitted.
|
||||
yield return new object[] { "MSIL", ProcessorArchitecture.MSIL };
|
||||
yield return new object[] { "msil", ProcessorArchitecture.MSIL };
|
||||
yield return new object[] { "mSiL", ProcessorArchitecture.MSIL };
|
||||
yield return new object[] { "x86", ProcessorArchitecture.X86 };
|
||||
yield return new object[] { "X86", ProcessorArchitecture.X86 };
|
||||
yield return new object[] { "IA64", ProcessorArchitecture.IA64 };
|
||||
yield return new object[] { "ia64", ProcessorArchitecture.IA64 };
|
||||
yield return new object[] { "Ia64", ProcessorArchitecture.IA64 };
|
||||
yield return new object[] { "Amd64", ProcessorArchitecture.Amd64 };
|
||||
yield return new object[] { "AMD64", ProcessorArchitecture.Amd64 };
|
||||
yield return new object[] { "aMd64", ProcessorArchitecture.Amd64 };
|
||||
yield return new object[] { "Arm", ProcessorArchitecture.Arm };
|
||||
yield return new object[] { "ARM", ProcessorArchitecture.Arm };
|
||||
yield return new object[] { "ArM", ProcessorArchitecture.Arm };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Ctor_ProcessorArchitecture_TestData))]
|
||||
public void Ctor_ValidArchitectureName_Succeeds(string architectureName, ProcessorArchitecture expected)
|
||||
{
|
||||
string fullName = "Test, ProcessorArchitecture=" + architectureName;
|
||||
AssemblyName assemblyName = new AssemblyName(fullName);
|
||||
Assert.Equal(expected, assemblyName.ProcessorArchitecture);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("None")]
|
||||
[InlineData("NONE")]
|
||||
[InlineData("NoNe")]
|
||||
[InlineData("null")]
|
||||
[InlineData("Bogus")]
|
||||
[InlineData("")]
|
||||
[InlineData("0")]
|
||||
[InlineData("1")]
|
||||
[InlineData("@!#$!@#$")]
|
||||
[InlineData("All your base are belong to us.")]
|
||||
public void Ctor_InvalidArchitecture_ThrowsFileLoadException(string invalidName)
|
||||
{
|
||||
string fullName = "Test, ProcessorArchitecture=" + invalidName;
|
||||
Assert.Throws<FileLoadException>(() => new AssemblyName(fullName));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AssemblyContentType.Default)]
|
||||
[InlineData(AssemblyContentType.WindowsRuntime)]
|
||||
public void ContentType(AssemblyContentType contentType)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName("MyAssemblyName");
|
||||
Assert.Equal(AssemblyContentType.Default, assemblyName.ContentType);
|
||||
assemblyName.ContentType = contentType;
|
||||
Assert.Equal(contentType, assemblyName.ContentType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentType_CurrentlyExecutingAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = Helpers.ExecutingAssembly.GetName();
|
||||
Assert.Equal(AssemblyContentType.Default, assemblyName.ContentType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentType_SystemRuntimeAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = Helpers.ExecutingAssembly.GetName();
|
||||
Assert.Equal(AssemblyContentType.Default, assemblyName.ContentType);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CultureName_TestData()
|
||||
{
|
||||
yield return new object[] { new AssemblyName("Test, Culture=en-US"), "en-US", null, null, "Test" };
|
||||
yield return new object[] { new AssemblyName("Test, Culture=en-US"), "en-US", "", "", "Test, Culture=neutral" };
|
||||
yield return new object[] { new AssemblyName("Test"), null, "en-US", "en-US", "Test, Culture=en-US" };
|
||||
yield return new object[] { new AssemblyName("Test"), null, "En-US", "en-US", "Test, Culture=en-US" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CultureName_TestData))]
|
||||
public void CultureName_Set(AssemblyName assemblyName, string originalCultureName, string cultureName, string expectedCultureName, string expectedEqualString)
|
||||
{
|
||||
Assert.Equal(originalCultureName, assemblyName.CultureName);
|
||||
assemblyName.CultureName = cultureName;
|
||||
Assert.Equal(expectedCultureName, assemblyName.CultureName);
|
||||
Assert.Equal(new AssemblyName(expectedEqualString).FullName, assemblyName.FullName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CultureName_Set_Invalid_ThrowsCultureNotFoundException()
|
||||
{
|
||||
var assemblyName = new AssemblyName("Test");
|
||||
Assert.Throws<CultureNotFoundException>(() => new AssemblyName("Test, Culture=NotAValidCulture"));
|
||||
Assert.Throws<CultureNotFoundException>(() => assemblyName.CultureName = "NotAValidCulture");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AssemblyNameFlags.None)]
|
||||
[InlineData(AssemblyNameFlags.PublicKey)]
|
||||
[InlineData(AssemblyNameFlags.Retargetable)]
|
||||
public void Flags(AssemblyNameFlags flags)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName("MyAssemblyName");
|
||||
Assert.Equal(AssemblyNameFlags.None, assemblyName.Flags);
|
||||
assemblyName.Flags = flags;
|
||||
Assert.Equal(flags, assemblyName.Flags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Flags_CurrentlyExecutingAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = Helpers.ExecutingAssembly.GetName();
|
||||
Assert.NotNull(assemblyName.Flags);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Names_TestData))]
|
||||
public void FullName(string name, string expectedName)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName(name);
|
||||
|
||||
string extended = $"{expectedName}, Culture=neutral, PublicKeyToken=null";
|
||||
Assert.True(assemblyName.FullName == expectedName || assemblyName.FullName == extended);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FullName_CurrentlyExecutingAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = typeof(AssemblyNameTests).GetTypeInfo().Assembly.GetName();
|
||||
Assert.StartsWith("System.Reflection.Tests", assemblyName.FullName);
|
||||
Assert.Equal(assemblyName.Name.Length, assemblyName.FullName.IndexOf(','));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> SetPublicKey_TestData()
|
||||
{
|
||||
yield return new object[] { null };
|
||||
yield return new object[] { new byte[0] };
|
||||
yield return new object[] { new byte[16] };
|
||||
yield return new object[] { Enumerable.Repeat((byte)'\0', 16).ToArray() };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(SetPublicKey_TestData))]
|
||||
public void SetPublicKey_GetPublicKey(byte[] publicKey)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName();
|
||||
assemblyName.SetPublicKey(publicKey);
|
||||
Assert.Equal(publicKey, assemblyName.GetPublicKey());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(SetPublicKey_TestData))]
|
||||
public void SetPublicKeyToken_GetPublicKeyToken(byte[] publicKeyToken)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName();
|
||||
assemblyName.SetPublicKeyToken(publicKeyToken);
|
||||
Assert.Equal(publicKeyToken, assemblyName.GetPublicKeyToken());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPublicKeyToken_CurrentlyExecutingAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = typeof(AssemblyNameTests).GetTypeInfo().Assembly.GetName();
|
||||
byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
|
||||
Assert.Equal(8, publicKeyToken.Length);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Names_TestData))]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("", "")]
|
||||
public void Name_Set(string name, string expectedName)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName("MyAssemblyName");
|
||||
assemblyName.Name = name;
|
||||
Assert.Equal(name, assemblyName.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Name_CurrentlyExecutingAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = typeof(AssemblyNameTests).GetTypeInfo().Assembly.GetName();
|
||||
Assert.StartsWith("System.Reflection.Tests", assemblyName.Name);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Version_TestData()
|
||||
{
|
||||
yield return new object[] { new Version(255, 1), "255.1.65535.65535" };
|
||||
yield return new object[] { new Version(255, 1, 2), "255.1.2.65535" };
|
||||
yield return new object[] { new Version(255, 1, 2, 3), "255.1.2.3" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Version_TestData))]
|
||||
public void Version(Version version, string versionString)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName("MyAssemblyName");
|
||||
assemblyName.Version = version;
|
||||
|
||||
string expected = "MyAssemblyName, Version=" + versionString;
|
||||
string extended = expected + ", Culture=neutral, PublicKeyToken=null";
|
||||
Assert.True(assemblyName.FullName == expected || assemblyName.FullName == extended);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Version_CurrentlyExecutingAssembly()
|
||||
{
|
||||
AssemblyName assemblyName = typeof(AssemblyNameTests).GetTypeInfo().Assembly.GetName();
|
||||
assemblyName.Version = new Version(255, 1, 2, 3);
|
||||
Assert.Contains("Version=255.1.2.3", assemblyName.FullName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Foo")]
|
||||
[InlineData("Hi There")]
|
||||
public void ToString(string name)
|
||||
{
|
||||
var assemblyName = new AssemblyName(name);
|
||||
Assert.StartsWith(name, assemblyName.ToString());
|
||||
Assert.Equal(assemblyName.FullName, assemblyName.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData((ProcessorArchitecture)(-1))]
|
||||
[InlineData((ProcessorArchitecture)int.MaxValue)]
|
||||
[InlineData((ProcessorArchitecture)int.MinValue)]
|
||||
[InlineData(CurrentMaxValue + 1)]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 0))]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 1))]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 2))]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 3))]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 4))]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 5))]
|
||||
[InlineData((ProcessorArchitecture)(~7 | 6))]
|
||||
public void SetProcessorArchitecture_InvalidArchitecture_TakesLowerThreeBitsIfLessThanOrEqualToMax(ProcessorArchitecture invalidArchitecture)
|
||||
{
|
||||
foreach (ProcessorArchitecture validArchitecture in ValidProcessorArchitectureValues())
|
||||
{
|
||||
var assemblyName = new AssemblyName();
|
||||
assemblyName.ProcessorArchitecture = validArchitecture;
|
||||
assemblyName.ProcessorArchitecture = invalidArchitecture;
|
||||
|
||||
ProcessorArchitecture maskedInvalidArchitecture = (ProcessorArchitecture)(((int)invalidArchitecture) & 0x7);
|
||||
ProcessorArchitecture expectedResult = maskedInvalidArchitecture > CurrentMaxValue ? validArchitecture : maskedInvalidArchitecture;
|
||||
|
||||
Assert.Equal(expectedResult, assemblyName.ProcessorArchitecture);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ProcessorArchitectures_TestData))]
|
||||
public void SetProcessorArchitecture_NoneArchitecture_Succeeds(ProcessorArchitecture architecture)
|
||||
{
|
||||
var assemblyName = new AssemblyName();
|
||||
|
||||
assemblyName.ProcessorArchitecture = architecture;
|
||||
assemblyName.ProcessorArchitecture = ProcessorArchitecture.None;
|
||||
|
||||
Assert.Equal(ProcessorArchitecture.None, assemblyName.ProcessorArchitecture);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Ctor_ProcessorArchitecture_TestData))]
|
||||
public void GetFullNameAndToString_AreEquivalentAndDoNotPreserveArchitecture(string name, ProcessorArchitecture expected)
|
||||
{
|
||||
string originalFullName = "Test, Culture=en-US, PublicKeyToken=b77a5c561934e089, ProcessorArchitecture=" + name;
|
||||
string expectedSerializedFullName = "Test, Culture=en-US, PublicKeyToken=b77a5c561934e089";
|
||||
|
||||
var assemblyName = new AssemblyName(originalFullName);
|
||||
|
||||
Assert.Equal(expectedSerializedFullName, assemblyName.FullName);
|
||||
Assert.Equal(expectedSerializedFullName, assemblyName.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ProcessorArchitectures_TestData))]
|
||||
public void SetProcessorArchitecture_ValidArchitecture_Succeeds(ProcessorArchitecture architecture)
|
||||
{
|
||||
AssemblyName assemblyName = new AssemblyName();
|
||||
assemblyName.ProcessorArchitecture = architecture;
|
||||
Assert.Equal(architecture, assemblyName.ProcessorArchitecture);
|
||||
}
|
||||
}
|
||||
}
|
340
external/corefx/src/System.Reflection/tests/AssemblyTests.cs
vendored
Normal file
340
external/corefx/src/System.Reflection/tests/AssemblyTests.cs
vendored
Normal file
@@ -0,0 +1,340 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Tests;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Xunit;
|
||||
|
||||
[assembly:
|
||||
Attr(77, name = "AttrSimple"),
|
||||
Int32Attr(77, name = "Int32AttrSimple"),
|
||||
Int64Attr(77, name = "Int64AttrSimple"),
|
||||
StringAttr("hello", name = "StringAttrSimple"),
|
||||
EnumAttr(PublicEnum.Case1, name = "EnumAttrSimple"),
|
||||
TypeAttr(typeof(object), name = "TypeAttrSimple")]
|
||||
[assembly: CompilationRelaxations(8)]
|
||||
[assembly: Debuggable((DebuggableAttribute.DebuggingModes)263)]
|
||||
[assembly: CLSCompliant(false)]
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class AssemblyTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(typeof(Int32Attr))]
|
||||
[InlineData(typeof(Int64Attr))]
|
||||
[InlineData(typeof(StringAttr))]
|
||||
[InlineData(typeof(EnumAttr))]
|
||||
[InlineData(typeof(TypeAttr))]
|
||||
[InlineData(typeof(CompilationRelaxationsAttribute))]
|
||||
[InlineData(typeof(AssemblyTitleAttribute))]
|
||||
[InlineData(typeof(AssemblyDescriptionAttribute))]
|
||||
[InlineData(typeof(AssemblyCompanyAttribute))]
|
||||
[InlineData(typeof(CLSCompliantAttribute))]
|
||||
[InlineData(typeof(DebuggableAttribute))]
|
||||
[InlineData(typeof(Attr))]
|
||||
public void CustomAttributes(Type type)
|
||||
{
|
||||
Assembly assembly = Helpers.ExecutingAssembly;
|
||||
IEnumerable<Type> attributesData = assembly.CustomAttributes.Select(customAttribute => customAttribute.AttributeType);
|
||||
Assert.Contains(type, attributesData);
|
||||
|
||||
ICustomAttributeProvider attributeProvider = assembly;
|
||||
Assert.Single(attributeProvider.GetCustomAttributes(type, false));
|
||||
Assert.True(attributeProvider.IsDefined(type, false));
|
||||
|
||||
IEnumerable<Type> customAttributes = attributeProvider.GetCustomAttributes(false).Select(attribute => attribute.GetType());
|
||||
Assert.Contains(type, customAttributes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(int), false)]
|
||||
[InlineData(typeof(Attr), true)]
|
||||
[InlineData(typeof(Int32Attr), true)]
|
||||
[InlineData(typeof(Int64Attr), true)]
|
||||
[InlineData(typeof(StringAttr), true)]
|
||||
[InlineData(typeof(EnumAttr), true)]
|
||||
[InlineData(typeof(TypeAttr), true)]
|
||||
[InlineData(typeof(ObjectAttr), true)]
|
||||
[InlineData(typeof(NullAttr), true)]
|
||||
public void DefinedTypes(Type type, bool expected)
|
||||
{
|
||||
IEnumerable<Type> customAttrs = Helpers.ExecutingAssembly.DefinedTypes.Select(typeInfo => typeInfo.AsType());
|
||||
|
||||
Assert.Equal(expected, customAttrs.Contains(type));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("EmbeddedImage.png", true)]
|
||||
[InlineData("NoSuchFile", false)]
|
||||
public void EmbeddedFiles(string resource, bool exists)
|
||||
{
|
||||
string[] resources = Helpers.ExecutingAssembly.GetManifestResourceNames();
|
||||
Stream resourceStream = Helpers.ExecutingAssembly.GetManifestResourceStream(resource);
|
||||
|
||||
Assert.Equal(exists, resources.Contains(resource));
|
||||
Assert.Equal(exists, resourceStream != null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EntryPoint_ExecutingAssembly_IsNull()
|
||||
{
|
||||
Assert.Null(Helpers.ExecutingAssembly.EntryPoint);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { Assembly.Load(new AssemblyName(typeof(int).GetTypeInfo().Assembly.FullName)), Assembly.Load(new AssemblyName(typeof(int).GetTypeInfo().Assembly.FullName)), true };
|
||||
yield return new object[] { Assembly.Load(new AssemblyName(typeof(List<int>).GetTypeInfo().Assembly.FullName)), Assembly.Load(new AssemblyName(typeof(List<int>).GetTypeInfo().Assembly.FullName)), true };
|
||||
yield return new object[] { Assembly.Load(new AssemblyName(typeof(List<int>).GetTypeInfo().Assembly.FullName)), Helpers.ExecutingAssembly, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals(Assembly assembly1, Assembly assembly2, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, assembly1.Equals(assembly2));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(AssemblyPublicClass), true)]
|
||||
[InlineData(typeof(AssemblyTests), true)]
|
||||
[InlineData(typeof(AssemblyPublicClass.PublicNestedClass), true)]
|
||||
[InlineData(typeof(PublicEnum), true)]
|
||||
[InlineData(typeof(AssemblyGenericPublicClass<>), true)]
|
||||
[InlineData(typeof(AssemblyInternalClass), false)]
|
||||
public void ExportedTypes(Type type, bool expected)
|
||||
{
|
||||
Assembly assembly = Helpers.ExecutingAssembly;
|
||||
Assert.Equal(assembly.GetExportedTypes(), assembly.ExportedTypes);
|
||||
|
||||
Assert.Equal(expected, assembly.ExportedTypes.Contains(type));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEntryAssembly()
|
||||
{
|
||||
Assert.NotNull(Assembly.GetEntryAssembly());
|
||||
Assert.StartsWith("xunit.console.netcore", Assembly.GetEntryAssembly().ToString(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetHashCode_TestData()
|
||||
{
|
||||
yield return new object[] { LoadSystemRuntimeAssembly() };
|
||||
yield return new object[] { LoadSystemCollectionsAssembly() };
|
||||
yield return new object[] { LoadSystemReflectionAssembly() };
|
||||
yield return new object[] { typeof(AssemblyTests).GetTypeInfo().Assembly };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetHashCode_TestData))]
|
||||
public void GetHashCode(Assembly assembly)
|
||||
{
|
||||
int hashCode = assembly.GetHashCode();
|
||||
Assert.NotEqual(-1, hashCode);
|
||||
Assert.NotEqual(0, hashCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("System.Reflection.Tests.AssemblyPublicClass", true)]
|
||||
[InlineData("System.Reflection.Tests.AssemblyInternalClass", true)]
|
||||
[InlineData("System.Reflection.Tests.PublicEnum", true)]
|
||||
[InlineData("System.Reflection.Tests.PublicStruct", true)]
|
||||
[InlineData("AssemblyPublicClass", false)]
|
||||
[InlineData("NoSuchType", false)]
|
||||
public void GetType(string name, bool exists)
|
||||
{
|
||||
Type type = Helpers.ExecutingAssembly.GetType(name);
|
||||
if (exists)
|
||||
{
|
||||
Assert.Equal(name, type.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(type);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> IsDynamic_TestData()
|
||||
{
|
||||
yield return new object[] { Helpers.ExecutingAssembly, false };
|
||||
yield return new object[] { LoadSystemCollectionsAssembly(), false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(IsDynamic_TestData))]
|
||||
public void IsDynamic(Assembly assembly, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, assembly.IsDynamic);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Load_TestData()
|
||||
{
|
||||
yield return new object[] { new AssemblyName(typeof(int).GetTypeInfo().Assembly.FullName) };
|
||||
yield return new object[] { new AssemblyName(typeof(List<int>).GetTypeInfo().Assembly.FullName) };
|
||||
yield return new object[] { new AssemblyName(typeof(AssemblyName).GetTypeInfo().Assembly.FullName) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Load_TestData))]
|
||||
public void Load(AssemblyName assemblyRef)
|
||||
{
|
||||
Assert.NotNull(Assembly.Load(assemblyRef));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Load_Invalid()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("assemblyRef", () => Assembly.Load((AssemblyName)null)); // AssemblyRef is null
|
||||
Assert.Throws<FileNotFoundException>(() => Assembly.Load(new AssemblyName("no such assembly"))); // No such assembly
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Location_ExecutingAssembly_IsNotNull()
|
||||
{
|
||||
// This test applies on all platforms including .NET Native. Location must at least be non-null (it can be empty).
|
||||
// System.Reflection.CoreCLR.Tests adds tests that expect more than that.
|
||||
Assert.NotNull(Helpers.ExecutingAssembly.Location);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CodeBase()
|
||||
{
|
||||
Assert.NotEmpty(Helpers.ExecutingAssembly.CodeBase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImageRuntimeVersion()
|
||||
{
|
||||
Assert.NotEmpty(Helpers.ExecutingAssembly.ImageRuntimeVersion);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CreateInstance_TestData()
|
||||
{
|
||||
yield return new object[] { Helpers.ExecutingAssembly, typeof(AssemblyPublicClass).FullName, typeof(AssemblyPublicClass) };
|
||||
yield return new object[] { typeof(int).GetTypeInfo().Assembly, typeof(int).FullName, typeof(int) };
|
||||
yield return new object[] { typeof(int).GetTypeInfo().Assembly, typeof(Dictionary<int, string>).FullName, typeof(Dictionary<int, string>) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CreateInstance_TestData))]
|
||||
public void CreateInstance(Assembly assembly, string typeName, Type expectedType)
|
||||
{
|
||||
Assert.IsType(expectedType, assembly.CreateInstance(typeName));
|
||||
Assert.IsType(expectedType, assembly.CreateInstance(typeName, false));
|
||||
Assert.IsType(expectedType, assembly.CreateInstance(typeName, true));
|
||||
|
||||
Assert.IsType(expectedType, assembly.CreateInstance(typeName.ToUpper(), true));
|
||||
Assert.IsType(expectedType, assembly.CreateInstance(typeName.ToLower(), true));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CreateInstance_Invalid_TestData()
|
||||
{
|
||||
yield return new object[] { "", typeof(ArgumentException) };
|
||||
yield return new object[] { null, typeof(ArgumentNullException) };
|
||||
yield return new object[] { typeof(AssemblyClassWithPrivateCtor).FullName, typeof(MissingMethodException) };
|
||||
yield return new object[] { typeof(AssemblyClassWithNoDefaultCtor).FullName, typeof(MissingMethodException) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CreateInstance_Invalid_TestData))]
|
||||
public void CreateInstance_Invalid(string typeName, Type exceptionType)
|
||||
{
|
||||
Assembly assembly = Helpers.ExecutingAssembly;
|
||||
Assert.Throws(exceptionType, () => Helpers.ExecutingAssembly.CreateInstance(typeName));
|
||||
Assert.Throws(exceptionType, () => Helpers.ExecutingAssembly.CreateInstance(typeName, true));
|
||||
Assert.Throws(exceptionType, () => Helpers.ExecutingAssembly.CreateInstance(typeName, false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateQualifiedName()
|
||||
{
|
||||
string assemblyName = Helpers.ExecutingAssembly.ToString();
|
||||
Assert.Equal(typeof(AssemblyTests).FullName + ", " + assemblyName, Assembly.CreateQualifiedName(assemblyName, typeof(AssemblyTests).FullName));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetReferencedAssemblies()
|
||||
{
|
||||
// It is too brittle to depend on the assembly references so we just call the method and check that it does not throw.
|
||||
AssemblyName[] assemblies = Helpers.ExecutingAssembly.GetReferencedAssemblies();
|
||||
Assert.NotEmpty(assemblies);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Modules_TestData()
|
||||
{
|
||||
yield return new object[] { LoadSystemCollectionsAssembly() };
|
||||
yield return new object[] { LoadSystemReflectionAssembly() };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Modules_TestData))]
|
||||
public void Modules(Assembly assembly)
|
||||
{
|
||||
Assert.NotEmpty(assembly.Modules);
|
||||
foreach (Module module in assembly.Modules)
|
||||
{
|
||||
Assert.NotNull(module);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
yield return new object[] { Helpers.ExecutingAssembly, "System.Reflection.Tests" };
|
||||
yield return new object[] { Assembly.Load(new AssemblyName(typeof(List<int>).GetTypeInfo().Assembly.FullName)), "PublicKeyToken=" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public void ToString(Assembly assembly, string expected)
|
||||
{
|
||||
Assert.Contains(expected, assembly.ToString());
|
||||
Assert.Equal(assembly.ToString(), assembly.FullName);
|
||||
}
|
||||
|
||||
private static Assembly LoadSystemCollectionsAssembly()
|
||||
{
|
||||
// Force System.collections to be linked statically
|
||||
List<int> li = new List<int>();
|
||||
li.Add(1);
|
||||
return Assembly.Load(new AssemblyName(typeof(List<int>).GetTypeInfo().Assembly.FullName));
|
||||
}
|
||||
|
||||
private static Assembly LoadSystemReflectionAssembly()
|
||||
{
|
||||
// Force System.Reflection to be linked statically
|
||||
return Assembly.Load(new AssemblyName(typeof(AssemblyName).GetTypeInfo().Assembly.FullName));
|
||||
}
|
||||
|
||||
private static Assembly LoadSystemRuntimeAssembly()
|
||||
{
|
||||
// Load System.Runtime
|
||||
return Assembly.Load(new AssemblyName(typeof(int).GetTypeInfo().Assembly.FullName)); ;
|
||||
}
|
||||
}
|
||||
|
||||
public struct PublicStruct { }
|
||||
|
||||
public class AssemblyPublicClass
|
||||
{
|
||||
public class PublicNestedClass { }
|
||||
}
|
||||
|
||||
public class AssemblyGenericPublicClass<T> { }
|
||||
internal class AssemblyInternalClass { }
|
||||
|
||||
public class AssemblyClassWithPrivateCtor
|
||||
{
|
||||
private AssemblyClassWithPrivateCtor() { }
|
||||
}
|
||||
|
||||
public class AssemblyClassWithNoDefaultCtor
|
||||
{
|
||||
public AssemblyClassWithNoDefaultCtor(int x) { }
|
||||
}
|
||||
}
|
109
external/corefx/src/System.Reflection/tests/Common.cs
vendored
Normal file
109
external/corefx/src/System.Reflection/tests/Common.cs
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public enum PublicEnum
|
||||
{
|
||||
Case1 = 1,
|
||||
Case2 = 2,
|
||||
Case3 = 3
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class Attr : Attribute
|
||||
{
|
||||
public Attr(int i)
|
||||
{
|
||||
value = i;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{value}, {name}";
|
||||
|
||||
public string name;
|
||||
public int value;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class Int32Attr : Attribute
|
||||
{
|
||||
public Int32Attr(int i)
|
||||
{
|
||||
value = i;
|
||||
}
|
||||
|
||||
public string name;
|
||||
public readonly int value;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class Int64Attr : Attribute
|
||||
{
|
||||
public Int64Attr(long l)
|
||||
{
|
||||
value = l;
|
||||
}
|
||||
|
||||
public string name;
|
||||
public readonly long value;
|
||||
|
||||
public override string ToString() => $"{value}, {name}";
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class EnumAttr : Attribute
|
||||
{
|
||||
public EnumAttr(PublicEnum e)
|
||||
{
|
||||
value = e;
|
||||
}
|
||||
|
||||
public string name;
|
||||
public readonly PublicEnum value;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class StringAttr : Attribute
|
||||
{
|
||||
public StringAttr(string s)
|
||||
{
|
||||
value = s;
|
||||
}
|
||||
|
||||
public string name;
|
||||
public readonly string value;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class TypeAttr : Attribute
|
||||
{
|
||||
public TypeAttr(Type t)
|
||||
{
|
||||
value = t;
|
||||
}
|
||||
|
||||
public string name;
|
||||
public readonly Type value;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class ObjectAttr : Attribute
|
||||
{
|
||||
public ObjectAttr(object v)
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
public string name;
|
||||
public readonly object value;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
public class NullAttr : Attribute { }
|
||||
|
||||
public class Helpers
|
||||
{
|
||||
public static Assembly ExecutingAssembly => typeof(Helpers).GetTypeInfo().Assembly;
|
||||
}
|
||||
}
|
8
external/corefx/src/System.Reflection/tests/Configurations.props
vendored
Normal file
8
external/corefx/src/System.Reflection/tests/Configurations.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard1.5;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
246
external/corefx/src/System.Reflection/tests/ConstructorInfoTests.cs
vendored
Normal file
246
external/corefx/src/System.Reflection/tests/ConstructorInfoTests.cs
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable 0414
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class ConstructorInfoTests
|
||||
{
|
||||
[Fact]
|
||||
public void ConstructorName()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.Equal(3, constructors.Length);
|
||||
foreach (ConstructorInfo constructorInfo in constructors)
|
||||
{
|
||||
Assert.Equal(ConstructorInfo.ConstructorName, constructorInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
ConstructorInfo[] methodSampleConstructors1 = GetConstructors(typeof(ClassWith3Constructors));
|
||||
ConstructorInfo[] methodSampleConstructors2 = GetConstructors(typeof(ClassWith3Constructors));
|
||||
yield return new object[] { methodSampleConstructors1[0], methodSampleConstructors2[0], true };
|
||||
yield return new object[] { methodSampleConstructors1[1], methodSampleConstructors2[1], true };
|
||||
yield return new object[] { methodSampleConstructors1[2], methodSampleConstructors2[2], true };
|
||||
yield return new object[] { methodSampleConstructors1[1], methodSampleConstructors2[2], false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals(ConstructorInfo constructorInfo1, ConstructorInfo constructorInfo2, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, constructorInfo1.Equals(constructorInfo2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCodeTest()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
foreach (ConstructorInfo constructorInfo in constructors)
|
||||
{
|
||||
Assert.NotEqual(0, constructorInfo.GetHashCode());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.Equal(constructors.Length, 3);
|
||||
ClassWith3Constructors obj = (ClassWith3Constructors)constructors[0].Invoke(null);
|
||||
Assert.NotNull(obj);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_StaticConstructor_NullObject_NullParameters()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWithStaticConstructor));
|
||||
object obj = constructors[0].Invoke(null, new object[] { });
|
||||
Assert.Null(obj);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_StaticConstructor_ThrowsMemberAccessException()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWithStaticConstructor));
|
||||
Assert.Throws<MemberAccessException>(() => constructors[0].Invoke(new object[0]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_OneDimensionalArray()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(object[]));
|
||||
int[] arraylength = { 1, 2, 99, 65535 };
|
||||
|
||||
// Try to invoke Array ctors with different lengths
|
||||
foreach (int length in arraylength)
|
||||
{
|
||||
// Create big Array with elements
|
||||
object[] arr = (object[])constructors[0].Invoke(new object[] { length });
|
||||
Assert.Equal(arr.Length, length);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_OneDimensionalArray_NegativeLengths_ThrowsOverflowException()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(object[]));
|
||||
int[] arraylength = new int[] { -1, -2, -99 };
|
||||
// Try to invoke Array ctors with different lengths
|
||||
foreach (int length in arraylength)
|
||||
{
|
||||
// Create big Array with elements
|
||||
Assert.Throws<OverflowException>(() => (object[])constructors[0].Invoke(new object[] { length }));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_OneParameter()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
ClassWith3Constructors obj = (ClassWith3Constructors)constructors[1].Invoke(new object[] { 100 });
|
||||
Assert.Equal(obj.intValue, 100);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_TwoParameters()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
ClassWith3Constructors obj = (ClassWith3Constructors)constructors[2].Invoke(new object[] { 101, "hello" });
|
||||
Assert.Equal(obj.intValue, 101);
|
||||
Assert.Equal(obj.stringValue, "hello");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_NoParameters_ThowsTargetParameterCountException()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.Throws<TargetParameterCountException>(() => constructors[2].Invoke(new object[0]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_ParameterMismatch_ThrowsTargetParameterCountException()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.Throws<TargetParameterCountException>(() => (ClassWith3Constructors)constructors[2].Invoke(new object[] { 121 }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_ParameterWrongType_ThrowsArgumentException()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.Throws<ArgumentException>(null, () => (ClassWith3Constructors)constructors[1].Invoke(new object[] { "hello" }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_ExistingInstance()
|
||||
{
|
||||
// Should not prouce a second object.
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
ClassWith3Constructors obj1 = new ClassWith3Constructors(100, "hello");
|
||||
ClassWith3Constructors obj2 = (ClassWith3Constructors)constructors[2].Invoke(obj1, new object[] { 999, "initialized" });
|
||||
Assert.Null(obj2);
|
||||
Assert.Equal(obj1.intValue, 999);
|
||||
Assert.Equal(obj1.stringValue, "initialized");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_AbstractClass_ThrowsMemberAccessException()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ConstructorInfoAbstractBase));
|
||||
Assert.Throws<MemberAccessException>(() => (ConstructorInfoAbstractBase)constructors[0].Invoke(new object[0]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_SubClass()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ConstructorInfoDerived));
|
||||
ConstructorInfoDerived obj = null;
|
||||
obj = (ConstructorInfoDerived)constructors[0].Invoke(new object[] { });
|
||||
Assert.NotNull(obj);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Invoke_Struct()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(StructWith1Constructor));
|
||||
StructWith1Constructor obj;
|
||||
obj = (StructWith1Constructor)constructors[0].Invoke(new object[] { 1, 2 });
|
||||
Assert.Equal(1, obj.x);
|
||||
Assert.Equal(2, obj.y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsConstructor_ReturnsTrue()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.All(constructors, constructorInfo => Assert.True(constructorInfo.IsConstructor));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsPublic()
|
||||
{
|
||||
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
|
||||
Assert.True(constructors[0].IsPublic);
|
||||
}
|
||||
|
||||
public static ConstructorInfo[] GetConstructors(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().DeclaredConstructors.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
// Metadata for Reflection
|
||||
public abstract class ConstructorInfoAbstractBase
|
||||
{
|
||||
public ConstructorInfoAbstractBase() { }
|
||||
}
|
||||
|
||||
public class ConstructorInfoDerived : ConstructorInfoAbstractBase
|
||||
{
|
||||
public ConstructorInfoDerived() { }
|
||||
}
|
||||
|
||||
public class ClassWith3Constructors
|
||||
{
|
||||
public int intValue = 0;
|
||||
public string stringValue = "";
|
||||
|
||||
public ClassWith3Constructors() { }
|
||||
|
||||
public ClassWith3Constructors(int intValue) { this.intValue = intValue; }
|
||||
|
||||
public ClassWith3Constructors(int intValue, string stringValue)
|
||||
{
|
||||
this.intValue = intValue;
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public string Method1(DateTime dt) => "";
|
||||
}
|
||||
|
||||
public class ClassWithStaticConstructor
|
||||
{
|
||||
static ClassWithStaticConstructor() { }
|
||||
}
|
||||
|
||||
public struct StructWith1Constructor
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public StructWith1Constructor(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
}
|
58
external/corefx/src/System.Reflection/tests/CoreCLR/AssemblyTests.CoreCLR.cs
vendored
Normal file
58
external/corefx/src/System.Reflection/tests/CoreCLR/AssemblyTests.CoreCLR.cs
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.Loader;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class AssemblyTests
|
||||
{
|
||||
[Fact]
|
||||
public void CurrentLocation_HasLocaton()
|
||||
{
|
||||
string location = GetExecutingAssembly().Location;
|
||||
Assert.NotEmpty(location);
|
||||
string actualDir = Path.GetDirectoryName(location);
|
||||
|
||||
// Check that location is not relative
|
||||
Assert.True(Path.IsPathRooted(actualDir));
|
||||
Assert.Equal("System.Reflection.CoreCLR.Tests.dll", Path.GetFileName(location), StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadFromStream_Location_IsEmpty()
|
||||
{
|
||||
Assembly assembly = new TestStreamLoadContext().LoadFromAssemblyName(new AssemblyName("TinyAssembly"));
|
||||
Assert.Empty(assembly.Location);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DynamicAssembly_Location_ThrowsNotSupportedException()
|
||||
{
|
||||
AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("dynamic"), AssemblyBuilderAccess.Run);
|
||||
Assert.Throws<NotSupportedException>(() => builder.Location);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EntryPoint()
|
||||
{
|
||||
MethodInfo entryPoint = typeof(TestExe).GetTypeInfo().Assembly.EntryPoint;
|
||||
Assert.NotNull(entryPoint);
|
||||
Assert.Equal(42, entryPoint.Invoke(null, null));
|
||||
}
|
||||
|
||||
private static Assembly GetExecutingAssembly() => typeof(AssemblyTests).GetTypeInfo().Assembly;
|
||||
|
||||
private sealed class TestStreamLoadContext : AssemblyLoadContext
|
||||
{
|
||||
protected override Assembly Load(AssemblyName assemblyName)
|
||||
{
|
||||
return LoadFromStream(GetExecutingAssembly().GetManifestResourceStream(assemblyName.Name + ".dll"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
external/corefx/src/System.Reflection/tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
vendored
Normal file
31
external/corefx/src/System.Reflection/tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{C8049356-559D-4F34-AC17-56F3AE62C897}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<!-- Default configurations to help VS understand the configurations -->
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyTests.CoreCLR.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\..\..\Common\tests\Data\TinyAssembly.dll">
|
||||
<Link>Assembly\TinyAssembly.dll</Link>
|
||||
<LogicalName>TinyAssembly.dll</LogicalName>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TestExe\System.Reflection.TestExe.csproj">
|
||||
<Project>{8c19b991-41e9-4b38-9602-e19375397f1d}</Project>
|
||||
<Name>System.Reflection.Tests.TestExe</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
203
external/corefx/src/System.Reflection/tests/EventInfoTests.cs
vendored
Normal file
203
external/corefx/src/System.Reflection/tests/EventInfoTests.cs
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class EventInfoTests
|
||||
{
|
||||
public static IEnumerable<object[]> Events_TestData()
|
||||
{
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent) };
|
||||
yield return new object[] { typeof(BaseClass), "PrivateEvent" };
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicStaticEvent) };
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicVirtualEvent) };
|
||||
yield return new object[] { typeof(SubClass), nameof(BaseClass.PublicEvent) };
|
||||
yield return new object[] { typeof(SubClass), nameof(SubClass.EventPublicNew) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Events_TestData))]
|
||||
public void IsMulticast_ReturnsTrue(Type type, string name)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.True(eventInfo.IsMulticast);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(BaseClass), nameof(BaseClass.PublicEvent), true)]
|
||||
[InlineData(typeof(BaseClass), "PrivateEvent", false)]
|
||||
public void GetAddMethod(Type type, string name, bool isVisible)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.Equal(isVisible, eventInfo.GetAddMethod() != null);
|
||||
Assert.Equal(isVisible, eventInfo.GetAddMethod(false) != null);
|
||||
Assert.NotNull(eventInfo.GetAddMethod(true));
|
||||
|
||||
MethodInfo addMethod = eventInfo.AddMethod;
|
||||
Assert.Equal(addMethod, eventInfo.GetAddMethod(true));
|
||||
if (addMethod != null)
|
||||
{
|
||||
Assert.Equal("add_" + name, addMethod.Name);
|
||||
Assert.Equal(1, addMethod.GetParameters().Length);
|
||||
Assert.Equal(typeof(void), addMethod.ReturnParameter.ParameterType);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(BaseClass), nameof(BaseClass.PublicEvent), true)]
|
||||
[InlineData(typeof(BaseClass), "PrivateEvent", false)]
|
||||
public void GetRemoveMethod(Type type, string name, bool isVisible)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.Equal(isVisible, eventInfo.GetRemoveMethod() != null);
|
||||
Assert.Equal(isVisible, eventInfo.GetRemoveMethod(false) != null);
|
||||
Assert.NotNull(eventInfo.GetRemoveMethod(true));
|
||||
|
||||
MethodInfo removeMethod = eventInfo.RemoveMethod;
|
||||
Assert.Equal(removeMethod, eventInfo.GetRemoveMethod(true));
|
||||
if (removeMethod != null)
|
||||
{
|
||||
Assert.Equal("remove_" + name, removeMethod.Name);
|
||||
Assert.Equal(1, removeMethod.GetParameters().Length);
|
||||
Assert.Equal(typeof(void), removeMethod.ReturnParameter.ParameterType);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Events_TestData))]
|
||||
public void GetRaiseMethod(Type type, string name)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.Null(eventInfo.GetRaiseMethod(false));
|
||||
Assert.Null(eventInfo.GetRaiseMethod(true));
|
||||
|
||||
Assert.Equal(eventInfo.GetRaiseMethod(true), eventInfo.RaiseMethod);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> AddRemove_TestData()
|
||||
{
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), new BaseClass() };
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicStaticEvent), null };
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicVirtualEvent), new BaseClass() };
|
||||
yield return new object[] { typeof(SubClass), nameof(SubClass.EventPublicNew), new SubClass() };
|
||||
yield return new object[] { typeof(SubClass), nameof(SubClass.PublicEvent), new SubClass() };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AddRemove_TestData))]
|
||||
public void AddRemove(Type type, string name, object target)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
EventHandler handler = new EventHandler(ObjectEventArgsHandler);
|
||||
eventInfo.AddEventHandler(target, handler);
|
||||
eventInfo.RemoveEventHandler(target, handler);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> AddEventHandler_Invalid_TestData()
|
||||
{
|
||||
// Target is null
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), null, new EventHandler(ObjectEventArgsHandler), typeof(TargetException) };
|
||||
|
||||
// Handler is incorrect
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), "hello", new EventHandler(ObjectEventArgsHandler), typeof(TargetException) };
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), new BaseClass(), new ObjectDelegate(ObjectHandler), typeof(ArgumentException) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AddEventHandler_Invalid_TestData))]
|
||||
public void AddEventHandler_Invalid(Type type, string name, object target, Delegate handler, Type exceptionType)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.Throws(exceptionType, () => eventInfo.AddEventHandler(target, handler));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> RemoveEventHandler_Invalid_TestData()
|
||||
{
|
||||
// Target is null
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), new BaseClass(), new EventHandler(ObjectEventArgsHandler), null, new EventHandler(ObjectEventArgsHandler), typeof(TargetException) };
|
||||
|
||||
// Target is incorrect
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), new BaseClass(), new EventHandler(ObjectEventArgsHandler), "hello", new EventHandler(ObjectEventArgsHandler), typeof(TargetException) };
|
||||
|
||||
// Handler is incorrect
|
||||
yield return new object[] { typeof(BaseClass), nameof(BaseClass.PublicEvent), new BaseClass(), new EventHandler(ObjectEventArgsHandler), new BaseClass(), new ObjectDelegate(ObjectHandler), typeof(ArgumentException) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RemoveEventHandler_Invalid_TestData))]
|
||||
public void RemovEventHandler_Invalid(Type type, string name, object addTarget, Delegate addHandler, object removeTarget, Delegate removeHandler, Type exceptionType)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
eventInfo.AddEventHandler(addTarget, addHandler);
|
||||
|
||||
Assert.Throws(exceptionType, () => eventInfo.RemoveEventHandler(removeTarget, removeHandler));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(BaseClass), nameof(BaseClass.PublicEvent), typeof(BaseClass), nameof(BaseClass.PublicEvent), true)]
|
||||
[InlineData(typeof(BaseClass), nameof(BaseClass.PublicEvent), typeof(SubClass), nameof(SubClass.PublicEvent), false)]
|
||||
[InlineData(typeof(BaseClass), nameof(BaseClass.PublicEvent), typeof(BaseClass), nameof(BaseClass.PublicStaticEvent), false)]
|
||||
public void Equals(Type type1, string name1, Type type2, string name2, bool expected)
|
||||
{
|
||||
EventInfo eventInfo1 = GetEventInfo(type1, name1);
|
||||
EventInfo eventInfo2 = GetEventInfo(type2, name2);
|
||||
Assert.Equal(expected, eventInfo1.Equals(eventInfo2));
|
||||
Assert.Equal(expected, eventInfo1.GetHashCode().Equals(eventInfo2.GetHashCode()));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Events_TestData))]
|
||||
public void EventHandlerType(Type type, string name)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.Equal(typeof(EventHandler), eventInfo.EventHandlerType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Events_TestData))]
|
||||
public void Attributes(Type type, string name)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.Equal(EventAttributes.None, eventInfo.Attributes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Events_TestData))]
|
||||
public void IsSpecialName_NormalEvent_ReturnsFalse(Type type, string name)
|
||||
{
|
||||
EventInfo eventInfo = GetEventInfo(type, name);
|
||||
Assert.False(eventInfo.IsSpecialName);
|
||||
}
|
||||
|
||||
private static void ObjectEventArgsHandler(object o, EventArgs e) { }
|
||||
private static void ObjectHandler(object o) { }
|
||||
public delegate void ObjectDelegate(object o);
|
||||
|
||||
private static EventInfo GetEventInfo(Type declaringType, string eventName)
|
||||
{
|
||||
TypeInfo type = declaringType.GetTypeInfo();
|
||||
return type.DeclaredEvents.First(declaredEvent => declaredEvent.Name == eventName);
|
||||
}
|
||||
|
||||
#pragma warning disable 0067
|
||||
protected class BaseClass
|
||||
{
|
||||
private event EventHandler PrivateEvent;
|
||||
public event EventHandler PublicEvent;
|
||||
public static event EventHandler PublicStaticEvent;
|
||||
public virtual event EventHandler PublicVirtualEvent;
|
||||
}
|
||||
|
||||
protected class SubClass : BaseClass
|
||||
{
|
||||
public new event EventHandler PublicEvent;
|
||||
public event EventHandler EventPublicNew;
|
||||
}
|
||||
#pragma warning restore 0067
|
||||
}
|
||||
}
|
94
external/corefx/src/System.Reflection/tests/ExceptionTests.cs
vendored
Normal file
94
external/corefx/src/System.Reflection/tests/ExceptionTests.cs
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public static class ExceptionTests
|
||||
{
|
||||
[Fact]
|
||||
public static void TargetException()
|
||||
{
|
||||
TargetException ex = new TargetException();
|
||||
|
||||
Assert.NotEmpty(ex.Message);
|
||||
Assert.Null(ex.InnerException);
|
||||
|
||||
TargetException caught = Assert.Throws<TargetException>(() => ThrowGivenException(ex));
|
||||
Assert.Same(ex, caught);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TargetException_Message()
|
||||
{
|
||||
string message = "message";
|
||||
TargetException ex = new TargetException(message);
|
||||
|
||||
Assert.Equal(message, ex.Message);
|
||||
Assert.Null(ex.InnerException);
|
||||
|
||||
TargetException caught = Assert.Throws<TargetException>(() => ThrowGivenException(ex));
|
||||
Assert.Same(ex, caught);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TargetException_Message_InnerException()
|
||||
{
|
||||
string message = "message";
|
||||
Exception inner = new Exception();
|
||||
TargetException ex = new TargetException(message, inner);
|
||||
|
||||
Assert.Equal(message, ex.Message);
|
||||
Assert.Same(inner, ex.InnerException);
|
||||
|
||||
TargetException caught = Assert.Throws<TargetException>(() => ThrowGivenException(ex));
|
||||
Assert.Same(ex, caught);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void InvalidFilterCriteriaException()
|
||||
{
|
||||
InvalidFilterCriteriaException ex = new InvalidFilterCriteriaException();
|
||||
|
||||
Assert.NotEmpty(ex.Message);
|
||||
Assert.Null(ex.InnerException);
|
||||
|
||||
InvalidFilterCriteriaException caught = Assert.Throws<InvalidFilterCriteriaException>(() => ThrowGivenException(ex));
|
||||
Assert.Same(ex, caught);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void InvalidFilterCriteriaException_Message()
|
||||
{
|
||||
string message = "message";
|
||||
InvalidFilterCriteriaException ex = new InvalidFilterCriteriaException(message);
|
||||
|
||||
Assert.Equal(message, ex.Message);
|
||||
Assert.Null(ex.InnerException);
|
||||
|
||||
InvalidFilterCriteriaException caught = Assert.Throws<InvalidFilterCriteriaException>(() => ThrowGivenException(ex));
|
||||
Assert.Same(ex, caught);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void InvalidFilterCriteriaException_Message_InnerException()
|
||||
{
|
||||
string message = "message";
|
||||
Exception inner = new Exception();
|
||||
InvalidFilterCriteriaException ex = new InvalidFilterCriteriaException(message, inner);
|
||||
|
||||
Assert.Equal(message, ex.Message);
|
||||
Assert.Same(inner, ex.InnerException);
|
||||
|
||||
InvalidFilterCriteriaException caught = Assert.Throws<InvalidFilterCriteriaException>(() => ThrowGivenException(ex));
|
||||
Assert.Same(ex, caught);
|
||||
}
|
||||
|
||||
private static void ThrowGivenException(Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
526
external/corefx/src/System.Reflection/tests/FieldInfoTests.cs
vendored
Normal file
526
external/corefx/src/System.Reflection/tests/FieldInfoTests.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
310
external/corefx/src/System.Reflection/tests/GetTypeTests.cs
vendored
Normal file
310
external/corefx/src/System.Reflection/tests/GetTypeTests.cs
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class GetTypeTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetType_EmptyString()
|
||||
{
|
||||
Assembly a = typeof(GetTypeTests).GetTypeInfo().Assembly;
|
||||
Module m = a.ManifestModule;
|
||||
|
||||
string typeName = "";
|
||||
string aqn = ", " + typeof(GetTypeTests).GetTypeInfo().Assembly.FullName;
|
||||
|
||||
// Type.GetType
|
||||
Assert.Null(Type.GetType(typeName));
|
||||
Assert.Null(Type.GetType(aqn));
|
||||
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => Type.GetType(aqn, throwOnError: true));
|
||||
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: true));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true, ignoreCase: true));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => Type.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => Type.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
|
||||
// Assembly.GetType
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(typeName));
|
||||
Assert.Null(a.GetType(aqn));
|
||||
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(typeName, throwOnError: false, ignoreCase: true));
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(typeName, throwOnError: true, ignoreCase: true));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => a.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => a.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
|
||||
// Module.GetType
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(typeName, throwOnError: false, ignoreCase: true));
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(typeName, throwOnError: true, ignoreCase: true));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => m.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>("typeName@0", () => m.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetType_TestData()
|
||||
{
|
||||
yield return new object[] { "non-existent-type", null };
|
||||
yield return new object[] { typeof(MyClass1).FullName, typeof(MyClass1) };
|
||||
yield return new object[] { "System.Reflection.Tests.mYclAss1", typeof(MyClass1) };
|
||||
yield return new object[] { "System.Reflection.Tests.MyNameSPACe1.MyNAMEspace99.MyClASs3+inNer", null };
|
||||
yield return new object[] { "System.Reflection.Tests.MyNameSPACe1.MyNAMEspace2.MyClASs399+inNer", null };
|
||||
yield return new object[] { "System.Reflection.Tests.MyNameSPACe1.MyNAMEspace2.MyClASs3+inNer99", null };
|
||||
yield return new object[] { typeof(MyNamespace1.MyNamespace2.MyClass2).FullName, typeof(MyNamespace1.MyNamespace2.MyClass2) };
|
||||
yield return new object[] { typeof(MyNamespace1.MyNamespace2.MyClass3.iNner).FullName, typeof(MyNamespace1.MyNamespace2.MyClass3.iNner) };
|
||||
yield return new object[] { "System.Reflection.Tests.MyNameSPACe1.MyNAMEspace2.MyClASs3+inNer", typeof(MyNamespace1.MyNamespace2.MyClass3.iNner) };
|
||||
yield return new object[] { typeof(MyNamespace1.MyNamespace3.Foo).FullName, typeof(MyNamespace1.MyNamespace3.Foo) };
|
||||
yield return new object[] { "System.Reflection.Tests.mynamespace1.mynamespace3.foo", typeof(MyNamespace1.MyNamespace3.Foo) };
|
||||
yield return new object[] { "System.Reflection.Tests.MYNAMESPACE1.MYNAMESPACE3.FOO", typeof(MyNamespace1.MyNamespace3.Foo) };
|
||||
|
||||
Type type = typeof(MyNamespace1.MynAmespace3.Goo<int>);
|
||||
yield return new object[] { type.FullName, type };
|
||||
yield return new object[] { type.FullName.ToUpper(), type };
|
||||
yield return new object[] { type.FullName.ToLower(), type };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetType_TestData))]
|
||||
public void GetType(string typeName, Type expectedResult)
|
||||
{
|
||||
Assembly a = typeof(GetTypeTests).GetTypeInfo().Assembly;
|
||||
Module m = a.ManifestModule;
|
||||
|
||||
string aqn = typeName + ", " + a.FullName;
|
||||
if (expectedResult == null)
|
||||
{
|
||||
// Type.GetType
|
||||
Assert.Null(Type.GetType(typeName));
|
||||
Assert.Null(Type.GetType(aqn));
|
||||
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true));
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(aqn, throwOnError: true));
|
||||
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: true));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true, ignoreCase: true));
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
|
||||
// Assembly.GetType
|
||||
Assert.Null(a.GetType(typeName));
|
||||
Assert.Null(a.GetType(aqn));
|
||||
|
||||
Assert.Null(a.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(a.GetType(typeName, throwOnError: false, ignoreCase: true));
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => a.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<TypeLoadException>(() => a.GetType(typeName, throwOnError: true, ignoreCase: true));
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
|
||||
// Module.GetType
|
||||
Assert.Null(m.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(m.GetType(typeName, throwOnError: false, ignoreCase: true));
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => m.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<TypeLoadException>(() => m.GetType(typeName, throwOnError: true, ignoreCase: true));
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
}
|
||||
else if (expectedResult.FullName == typeName)
|
||||
{
|
||||
// Case-sensitive match.
|
||||
// Type.GetType
|
||||
Assert.Equal(expectedResult, Type.GetType(typeName));
|
||||
Assert.Equal(expectedResult, Type.GetType(aqn));
|
||||
|
||||
Assert.Equal(expectedResult, Type.GetType(typeName, throwOnError: false));
|
||||
Assert.Equal(expectedResult, Type.GetType(aqn, throwOnError: false));
|
||||
|
||||
Assert.Equal(expectedResult, Type.GetType(typeName, throwOnError: true));
|
||||
Assert.Equal(expectedResult, Type.GetType(aqn, throwOnError: true));
|
||||
|
||||
// When called with "ignoreCase: true", GetType() may have a choice of matching items. The one that is chosen
|
||||
// is an implementation detail (and on the CLR, *very* implementation-dependent as it's influenced by the internal
|
||||
// layout of private hash tables.) As a result, we do not expect the same result across desktop and Project N
|
||||
// and so the best we can do is compare the names.
|
||||
string expectedName = expectedResult.AssemblyQualifiedName;
|
||||
|
||||
Assert.Equal(expectedResult, Type.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(typeName, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Equal(expectedResult, Type.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(aqn, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
Assert.Equal(expectedResult, Type.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Equal(expectedResult, Type.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(aqn, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Assembly.GetType
|
||||
Assert.Equal(expectedResult, a.GetType(typeName));
|
||||
Assert.Null(a.GetType(aqn));
|
||||
|
||||
Assert.Equal(expectedResult, a.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, a.GetType(typeName, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Equal(expectedResult, a.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, a.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
|
||||
// Module.GetType
|
||||
Assert.Equal(expectedResult, m.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, m.GetType(typeName, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Equal(expectedResult, m.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, m.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
}
|
||||
else if (expectedResult.FullName.Equals(typeName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Case-insensitive match.
|
||||
// Type.GetType
|
||||
Assert.Null(Type.GetType(typeName));
|
||||
Assert.Null(Type.GetType(aqn));
|
||||
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false));
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true));
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(aqn, throwOnError: true));
|
||||
|
||||
// When called with "ignoreCase: true", GetType() may have a choice of matching items. The one that is chosen
|
||||
// is an implementation detail (and on the CLR, *very* implementation-dependent as it's influenced by the internal
|
||||
// layout of private hash tables.) As a result, we do not expect the same result across desktop and Project N
|
||||
// and so the best we can do is compare the names.
|
||||
string expectedName = expectedResult.AssemblyQualifiedName;
|
||||
|
||||
Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(typeName, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Null(Type.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(aqn, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Throws<TypeLoadException>(() => Type.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, Type.GetType(aqn, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Assembly.GetType
|
||||
Assert.Null(a.GetType(typeName));
|
||||
Assert.Null(a.GetType(aqn));
|
||||
|
||||
Assert.Null(a.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, a.GetType(typeName, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => a.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, a.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
|
||||
// Module.GetType
|
||||
Assert.Null(m.GetType(typeName, throwOnError: false, ignoreCase: false));
|
||||
Assert.Equal(expectedName, m.GetType(typeName, throwOnError: false, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: false));
|
||||
Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: true));
|
||||
|
||||
Assert.Throws<TypeLoadException>(() => m.GetType(typeName, throwOnError: true, ignoreCase: false));
|
||||
Assert.Equal(expectedName, m.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: false));
|
||||
Assert.Throws<ArgumentException>(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: true));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("TEST ERROR.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetType_CoreAssembly()
|
||||
{
|
||||
Assert.Equal(typeof(int), Type.GetType("System.Int32", throwOnError: true));
|
||||
Assert.Equal(typeof(int), Type.GetType("system.int32", throwOnError: true, ignoreCase: true));
|
||||
}
|
||||
}
|
||||
|
||||
namespace MyNamespace1
|
||||
{
|
||||
namespace MyNamespace2
|
||||
{
|
||||
public class MyClass2 { }
|
||||
public class MyClass3
|
||||
{
|
||||
public class Inner { }
|
||||
public class inner { }
|
||||
public class iNner { }
|
||||
public class inNer { }
|
||||
}
|
||||
public class MyClass4 { }
|
||||
public class mYClass4 { }
|
||||
public class Myclass4 { }
|
||||
public class myCLass4 { }
|
||||
public class myClAss4 { }
|
||||
}
|
||||
|
||||
namespace MyNamespace3
|
||||
{
|
||||
public class Foo { }
|
||||
}
|
||||
|
||||
namespace MynAmespace3
|
||||
{
|
||||
public class Foo { }
|
||||
|
||||
public class Goo<T> { }
|
||||
public class gOo<T> { }
|
||||
public class goO<T> { }
|
||||
}
|
||||
|
||||
namespace MyNaMespace3
|
||||
{
|
||||
public class Foo { }
|
||||
}
|
||||
|
||||
namespace MyNamEspace3
|
||||
{
|
||||
public class Foo { }
|
||||
}
|
||||
}
|
||||
|
||||
public class MyClass1 { }
|
||||
}
|
35
external/corefx/src/System.Reflection/tests/ManifestResourceInfoTests.cs
vendored
Normal file
35
external/corefx/src/System.Reflection/tests/ManifestResourceInfoTests.cs
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Reflection.Tests
|
||||
{
|
||||
public class ManifestResourceInfoTests
|
||||
{
|
||||
[Fact]
|
||||
public void FileName()
|
||||
{
|
||||
Assembly assembly = typeof(ManifestResourceInfoTests).GetTypeInfo().Assembly;
|
||||
ManifestResourceInfo manifestResourceInfo = assembly.GetManifestResourceInfo("ResourceTextFile.txt");
|
||||
Assert.Null(manifestResourceInfo.FileName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReferencedAssembly()
|
||||
{
|
||||
Assembly assembly = typeof(ManifestResourceInfoTests).GetTypeInfo().Assembly;
|
||||
ManifestResourceInfo manifestResourceInfo = assembly.GetManifestResourceInfo("ResourceTextFile.txt");
|
||||
Assert.Null(manifestResourceInfo.ReferencedAssembly);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResourceLocation()
|
||||
{
|
||||
Assembly assembly = typeof(ManifestResourceInfoTests).GetTypeInfo().Assembly;
|
||||
ManifestResourceInfo manifestResourceInfo = assembly.GetManifestResourceInfo("ResourceTextFile.txt");
|
||||
Assert.Equal("Embedded, ContainedInManifestFile", manifestResourceInfo.ResourceLocation.ToString());
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user