Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edge case with referencing enums in another assembly #162

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MetadataProcessor.Tests/Core/Utility/DumperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void DumpAssemblyTest()
Assert.IsTrue(dumpFileContent.Contains("TypeRefProps [01000001]: Scope: 23000001 'System.Diagnostics.DebuggableAttribute'"));
Assert.IsTrue(dumpFileContent.Contains(": Scope: 23000002 'TestNFClassLibrary.ClassOnAnotherAssembly'"));

Assert.IsTrue(dumpFileContent.Contains(": Flags: 00001001 Extends: 0100000d Enclosed: 02000000 'TestNFApp.DummyCustomAttribute1'"));
Assert.IsTrue(dumpFileContent.Contains(": Flags: 00001001 Extends: 0100000f Enclosed: 02000000 'TestNFApp.DummyCustomAttribute1'"));

Assert.IsTrue(dumpFileContent.Contains(": Flags: 00001001 Extends: 0100000d Enclosed: 02000000 'TestNFApp.DummyCustomAttribute2'"));
Assert.IsTrue(dumpFileContent.Contains(": Flags: 00001001 Extends: 0100000f Enclosed: 02000000 'TestNFApp.DummyCustomAttribute2'"));

Assert.IsTrue(dumpFileContent.Contains(": Flags: 00001061 Extends: 01000000 Enclosed: 02000000 'TestNFApp.IOneClassOverAll'"));
Assert.IsTrue(dumpFileContent.Contains(": Flags: 000007c6 Impl: 00000000 RVA: 00000000 'get_DummyProperty' [I4( )]"));
Expand Down
21 changes: 21 additions & 0 deletions MetadataProcessor.Tests/TestNFApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using TestNFClassLibrary;

Expand Down Expand Up @@ -36,6 +37,26 @@ public static void Main()
// Reflection Tests
ReflectionTests();

////////////////////////////////////////////////
// Test enum in another assembly, same namespace
var enumTest = new TestEnumInAnotherAssembly();
enumTest.CallTestEnumInAnotherAssembly();

/////////////////////////////////////
// reference enum in another assembly
var x = (IAmAClassWithAnEnum.EnumA)1;

var messageType = (IAmAClassWithAnEnum.EnumA)0;
switch (messageType)
{
case IAmAClassWithAnEnum.EnumA.Test:
Console.WriteLine("all good");
break;

default:
break;
}

Debug.WriteLine("Exiting TestNFApp");
}

Expand Down
20 changes: 20 additions & 0 deletions MetadataProcessor.Tests/TestNFApp/TestEnumInAnotherAssembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.IO
{
public class TestEnumInAnotherAssembly
{
public void CallTestEnumInAnotherAssembly()
{
// This test checks if MDP can minimize the assembly using an enum that is defined in another assembly
// and the class calling it is in a different assembly BUT in the same namespace.
var ioException = new IOException(
string.Empty,
(int)IOException.IOExceptionErrorCode.DirectoryNotFound);
}
}

}
1 change: 1 addition & 0 deletions MetadataProcessor.Tests/TestNFApp/TestNFApp.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Compile Include="IOneClassOverAll.cs" />
<Compile Include="ComplexAttribute.cs" />
<Compile Include="MaxAttribute.cs" />
<Compile Include="TestEnumInAnotherAssembly.cs" />
<Compile Include="MyAttribute.cs" />
<Compile Include="MyClass1.cs" />
<Compile Include="OneClassOverAll.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace TestNFClassLibrary
{
public class IAmAClassWithAnEnum
{
public enum EnumA
{
Test = 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="IAmAClassWithAnEnum.cs" />
<Compile Include="ClassOnAnotherAssembly.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down