Skip to content

Commit

Permalink
Expose Assembly.GetEntryAssembly and TypeInfo.IsEquivalentTo()
Browse files Browse the repository at this point in the history
Expose Assembly.GetEntryAssembly and TypeInfo.IsEquivalentTo() in System.Reflection.
Fixes issues #4146 , #2101
  • Loading branch information
pallavit committed Dec 17, 2015
1 parent 4e6fcf2 commit cbc0260
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Common/test-runtime/project.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1-rc2-23610",
"Microsoft.NETCore.TestHost": "1.0.0-rc2-23610",
"Microsoft.NETCore.Console": "1.0.0-rc2-23610",
"System.IO.Compression": "4.1.0-rc2-23610",
"Microsoft.NETCore.Platforms": "1.0.1-rc2-23616",
"Microsoft.NETCore.TestHost": "1.0.0-rc2-23616",
"Microsoft.NETCore.Console": "1.0.0-rc2-23616",
"System.IO.Compression": "4.1.0-rc2-23616",
"coveralls.io": "1.4",
"OpenCover": "4.6.166",
"ReportGenerator": "2.3.4",
Expand Down
6 changes: 3 additions & 3 deletions src/System.Diagnostics.Contracts/src/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"frameworks": {
"dnxcore50": {
"dependencies": {
"Microsoft.TargetingPack.Private.CoreCLR": "1.0.0-rc2-23604"
"Microsoft.TargetingPack.Private.CoreCLR": "1.0.0-rc2-23616"
}
},
"netcore50": {
"dependencies": {
"Microsoft.TargetingPack.Private.CoreCLR": "1.0.0-rc2-23604"
"Microsoft.TargetingPack.Private.CoreCLR": "1.0.0-rc2-23616"
}
},
"net46": {
"dependencies": {
"Microsoft.TargetingPack.NETFramework.v4.6": "1.0.0-rc2-23530"
"Microsoft.TargetingPack.NETFramework.v4.6": "1.0.0-rc2-23616"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/System.Reflection/ref/System.Reflection.Manual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public partial class TypeInfo
public abstract System.Type GetElementType();
public abstract Type[] GetGenericParameterConstraints();
public virtual bool IsSubclassOf(System.Type c) { return default(bool); }
public virtual bool IsEquivalentTo(Type other) { return default(bool); }
public abstract Type[] GenericTypeArguments { get; }
public abstract Type GetGenericTypeDefinition();
public abstract Assembly Assembly { get; }
Expand Down
1 change: 1 addition & 0 deletions src/System.Reflection/ref/System.Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal Assembly() { }
public virtual System.Type GetType(string name) { return default(System.Type); }
public virtual System.Type GetType(string name, bool throwOnError, bool ignoreCase) { return default(System.Type); }
public static System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef) { return default(System.Reflection.Assembly); }
public static System.Reflection.Assembly GetEntryAssembly() { return default(System.Reflection.Assembly); }
public virtual string Location { get { return default(string); } }
public override string ToString() { return default(string); }
}
Expand Down
20 changes: 20 additions & 0 deletions src/System.Reflection/tests/Assembly/Assembly_GetEntryAssembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Xunit;
using System;
using System.Reflection;

namespace System.Reflection.Tests
{
public class AssemblyGetEntryAssemblyTest
{
[Fact]
public void Test_GetEntryAssembly()
{
Assert.NotNull(Assembly.GetEntryAssembly());
Assert.True(Assembly.GetEntryAssembly().ToString().StartsWith("xunit.console.netcore", StringComparison.OrdinalIgnoreCase));
}
}
}

2 changes: 2 additions & 0 deletions src/System.Reflection/tests/System.Reflection.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="Assembly\Assembly_LocationTests.cs" />
<Compile Include="Assembly\Assembly_ModulesTests.cs" />
<Compile Include="Assembly\Assembly_ToStringTests.cs" />
<Compile Include="Assembly\Assembly_GetEntryAssembly.cs" />
<Compile Include="Common\ReflectionTestData.cs" />
<Compile Include="ConstructorInfo\ConstructorInfo_FieldTests.cs" />
<Compile Include="ConstructorInfo\ConstructorInfo_InvokeTests.cs" />
Expand Down Expand Up @@ -83,6 +84,7 @@
<Compile Include="TypeInfo\TypeInfo_GenericTypeParametersTests.cs" />
<Compile Include="TypeInfo\TypeInfo_ImplementedInterfacesTests.cs" />
<Compile Include="TypeInfo\TypeInfo_IsAssignableFromTests.cs" />
<Compile Include="TypeInfo\TypeInfo_IsEquivalentTo.cs" />
<Compile Include="TypeInfo\TypeInfo_MethodTests.cs" />
<Compile Include="TypeInfo\TypeInfo_PropertyTests.cs" />
</ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions src/System.Reflection/tests/TypeInfo/TypeInfo_IsEquivalentTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Xunit;
using System;
using System.Reflection;
using System.Collections.Generic;

namespace System.Reflection.Tests
{
public class IsEquivalentToReflectionTests
{
[Fact]
public void IsEquivalentTo()
{
Assert.True(typeof(string).GetTypeInfo().IsEquivalentTo(typeof(string)));
Assert.False(typeof(object).GetTypeInfo().IsEquivalentTo(typeof(string)));

Object o = "stringAsObject";
string s = "stringAsString";

Assert.True(o.GetType().GetTypeInfo().IsEquivalentTo(s.GetType()));
Assert.True(typeof(IsEquivalentToReflectionTests.MyClass1).GetTypeInfo().IsEquivalentTo(typeof(IsEquivalentToReflectionTests.MyClass1)));
}

public class MyClass1 { }
}

}

0 comments on commit cbc0260

Please sign in to comment.