diff --git a/MiddleweightReflection.sln b/MiddleweightReflection.sln index 52a07d3..3c9885a 100644 --- a/MiddleweightReflection.sln +++ b/MiddleweightReflection.sln @@ -3,30 +3,108 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30204.135 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiddleweightReflection", "MiddleweightReflection\MiddleweightReflection.csproj", "{ACAEDCBA-8C46-4135-8577-30D37B86AE01}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiddleweightReflection", "MiddleweightReflection\MiddleweightReflection.csproj", "{ACAEDCBA-8C46-4135-8577-30D37B86AE01}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "Test\UnitTests.csproj", "{C5148951-A297-462F-BD72-0B3AA43F7215}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestSampleAssembly", "Test\UnitTestSampleAssembly\UnitTestSampleAssembly.csproj", "{65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestWinRTComponent", "Test\UnitTestWinRTComponent\UnitTestWinRTComponent.csproj", "{95C612FE-E84C-4923-9AB3-CD305B4F5C84}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|ARM.ActiveCfg = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|ARM.Build.0 = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|ARM64.Build.0 = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|x64.ActiveCfg = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|x64.Build.0 = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|x86.ActiveCfg = Debug|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Debug|x86.Build.0 = Debug|Any CPU {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|Any CPU.ActiveCfg = Release|Any CPU {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|Any CPU.Build.0 = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|ARM.ActiveCfg = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|ARM.Build.0 = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|ARM64.ActiveCfg = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|ARM64.Build.0 = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|x64.ActiveCfg = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|x64.Build.0 = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|x86.ActiveCfg = Release|Any CPU + {ACAEDCBA-8C46-4135-8577-30D37B86AE01}.Release|x86.Build.0 = Release|Any CPU {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|ARM.ActiveCfg = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|ARM.Build.0 = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|ARM64.Build.0 = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|x64.ActiveCfg = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|x64.Build.0 = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|x86.ActiveCfg = Debug|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Debug|x86.Build.0 = Debug|Any CPU {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|Any CPU.ActiveCfg = Release|Any CPU {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|Any CPU.Build.0 = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|ARM.ActiveCfg = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|ARM.Build.0 = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|ARM64.ActiveCfg = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|ARM64.Build.0 = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|x64.ActiveCfg = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|x64.Build.0 = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|x86.ActiveCfg = Release|Any CPU + {C5148951-A297-462F-BD72-0B3AA43F7215}.Release|x86.Build.0 = Release|Any CPU {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|ARM.ActiveCfg = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|ARM.Build.0 = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|ARM64.Build.0 = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|x64.ActiveCfg = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|x64.Build.0 = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|x86.ActiveCfg = Debug|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Debug|x86.Build.0 = Debug|Any CPU {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|Any CPU.ActiveCfg = Release|Any CPU {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|Any CPU.Build.0 = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|ARM.ActiveCfg = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|ARM.Build.0 = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|ARM64.ActiveCfg = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|ARM64.Build.0 = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|x64.ActiveCfg = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|x64.Build.0 = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|x86.ActiveCfg = Release|Any CPU + {65E7C87B-7E7B-4EEF-A6AA-5B8CD2F9D265}.Release|x86.Build.0 = Release|Any CPU + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|ARM.ActiveCfg = Debug|ARM + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|ARM.Build.0 = Debug|ARM + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|ARM64.Build.0 = Debug|ARM64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|x64.ActiveCfg = Debug|x64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|x64.Build.0 = Debug|x64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|x86.ActiveCfg = Debug|x86 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Debug|x86.Build.0 = Debug|x86 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|Any CPU.Build.0 = Release|Any CPU + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|ARM.ActiveCfg = Release|ARM + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|ARM.Build.0 = Release|ARM + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|ARM64.ActiveCfg = Release|ARM64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|ARM64.Build.0 = Release|ARM64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|x64.ActiveCfg = Release|x64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|x64.Build.0 = Release|x64 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|x86.ActiveCfg = Release|x86 + {95C612FE-E84C-4923-9AB3-CD305B4F5C84}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MiddleweightReflection/MrLoadContext.cs b/MiddleweightReflection/MrLoadContext.cs index c70076d..0a6a3e7 100644 --- a/MiddleweightReflection/MrLoadContext.cs +++ b/MiddleweightReflection/MrLoadContext.cs @@ -27,6 +27,21 @@ public MrLoadContext() LoadFromAssemblyName("mscorlib", implicitLoad: true); } + /// + /// A MRLoadContext into which can be loaded assemblies. If useWinRTProjections is set, + /// some types in a WinMD will be converted, for example IVector to IList. + /// + /// + public MrLoadContext(bool useWinRTProjections) + { + if(useWinRTProjections) + { + MetadataReaderOptions = MetadataReaderOptions.ApplyWindowsRuntimeProjections; + } + + LoadFromAssemblyName("mscorlib", implicitLoad: true); + } + /// /// Call this after loading assemblies, after which the LoadedAssemblies property will become non-null /// @@ -48,21 +63,6 @@ public void FinishLoading() } - /// - /// A MRLoadContext into which can be loaded assemblies. If useWinRTProjections is set, - /// some types in a WinMD will be converted, for example IVector to IList. - /// - /// - public MrLoadContext(bool useWinRTProjections = true) - { - if(!useWinRTProjections) - { - MetadataReaderOptions = MetadataReaderOptions.None; - } - - LoadFromAssemblyName("mscorlib", implicitLoad: true); - } - public delegate string AssemblyPathFromNameCallback(string assemblyName); public AssemblyPathFromNameCallback AssemblyPathFromName { get; set; } //public delegate string AssemblyPathFromNameCallback(string assemblyName); @@ -188,6 +188,24 @@ public MrAssembly LoadAssemblyFromPath(string path) return LoadFromReader(reader, name, path, implicitLoad: false); } + /// + /// Load an assembly from memory. If already loaded, return that. + /// + /// + /// + public MrAssembly LoadAssemblyFromBytes(byte[] buffer) + { + var reader = CreateReaderFromBytes(buffer); + var name = reader.GetString(reader.GetAssemblyDefinition().Name); + + if (_loadedAssemblies.TryGetValue(name, out var assembly)) + { + return assembly; + } + + return LoadFromReader(reader, name, null, implicitLoad: false); + } + /// /// Load given the assembly name. If already loaded, return that. /// @@ -326,13 +344,23 @@ void CreateReaderFromAssemblyName(string requestedName, out MetadataReader reade } /// - /// Create the System.Reflection.Metadata MetadataReader + /// Create the System.Reflection.Metadata MetadataReader give the path to an assembly /// /// /// unsafe MetadataReader CreateReaderFromPath(string path) { var buffer = File.ReadAllBytes(path); + return CreateReaderFromBytes(buffer); + } + + /// + /// Create the System.Reflection.Metadata MetadataReader given an in-memory assembly + /// + /// + /// + unsafe MetadataReader CreateReaderFromBytes(byte[] buffer) + { var pinnedHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); var headers = new PEHeaders(new MemoryStream(buffer)); var startOffset = headers.MetadataStartOffset; diff --git a/Test/Properties/Resources.Designer.cs b/Test/Properties/Resources.Designer.cs index 2dccbeb..fbf41f8 100644 --- a/Test/Properties/Resources.Designer.cs +++ b/Test/Properties/Resources.Designer.cs @@ -60,6 +60,29 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to + ///class <Module> + /// NotPublic + /// + ///public class UnitTestWinRTComponent.WinRTComponent : System.Object + /// AutoLayout, AnsiClass, Class, Public, Sealed, BeforeFieldInit + /// [MarshalingBehaviorAttribute] + /// [ThreadingAttribute] + /// [VersionAttribute(16777216)] + /// [ActivatableAttribute(16777216)] + /// UnitTestWinRTComponent.IWinRTComponentClass + /// UnitTestWinRTComponent.WinRTComponent() + /// System.Collections.Generic.IList<System.String> StringList { get; set; } + /// + ///class UnitTestWinRTComponent.<WinRT [rest of string was truncated]";. + /// + internal static string ExpectdProjectedWinRT { + get { + return ResourceManager.GetString("ExpectdProjectedWinRT", resourceCulture); + } + } + /// /// Looks up a localized string similar to ///class <Module> @@ -80,5 +103,38 @@ internal static string ExpectedOutput { return ResourceManager.GetString("ExpectedOutput", resourceCulture); } } + + /// + /// Looks up a localized string similar to + ///class <Module> + /// NotPublic + /// + ///class UnitTestWinRTComponent.<CLR>WinRTComponent : System.Object + /// AutoLayout, AnsiClass, Class, Sealed, SpecialName, BeforeFieldInit + /// [MarshalingBehaviorAttribute] + /// [ThreadingAttribute] + /// [VersionAttribute(16777216)] + /// [ActivatableAttribute(16777216)] + /// UnitTestWinRTComponent.IWinRTComponentClass + /// UnitTestWinRTComponent.<CLR>WinRTComponent() + /// System.Collections.Generic.IList<System.String> StringList { get; set; } + /// + ///public class UnitTestWinRTC [rest of string was truncated]";. + /// + internal static string ExpectedUnprojectedWinRT { + get { + return ResourceManager.GetString("ExpectedUnprojectedWinRT", resourceCulture); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] UnitTestWinRTComponent { + get { + object obj = ResourceManager.GetObject("UnitTestWinRTComponent", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/Test/Properties/Resources.resx b/Test/Properties/Resources.resx index d1453b2..cd66df8 100644 --- a/Test/Properties/Resources.resx +++ b/Test/Properties/Resources.resx @@ -118,7 +118,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\ExpectdProjectedWinRT.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + ..\Resources\ExpectedOutput.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + ..\Resources\ExpectedUnprojectedWinRT.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\UnitTestWinRTComponent.winmd;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Test/Resources/ExpectdProjectedWinRT.txt b/Test/Resources/ExpectdProjectedWinRT.txt new file mode 100644 index 0000000..9d06bec --- /dev/null +++ b/Test/Resources/ExpectdProjectedWinRT.txt @@ -0,0 +1,33 @@ + +class + NotPublic + +public class UnitTestWinRTComponent.WinRTComponent : System.Object + AutoLayout, AnsiClass, Class, Public, Sealed, BeforeFieldInit + [MarshalingBehaviorAttribute] + [ThreadingAttribute] + [VersionAttribute(16777216)] + [ActivatableAttribute(16777216)] + UnitTestWinRTComponent.IWinRTComponentClass + UnitTestWinRTComponent.WinRTComponent() + System.Collections.Generic.IList StringList { get; set; } + +class UnitTestWinRTComponent.WinRTComponent : System.Object + AutoLayout, AnsiClass, Class, Sealed, Import, WindowsRuntime, BeforeFieldInit + [MarshalingBehaviorAttribute] + [ThreadingAttribute] + [VersionAttribute(16777216)] + [CompilerGeneratedAttribute] + [ActivatableAttribute(16777216)] + UnitTestWinRTComponent.IWinRTComponentClass + Windows.Foundation.IStringable + UnitTestWinRTComponent.WinRTComponent() + System.Collections.Generic.IList StringList { get; set; } + +interface UnitTestWinRTComponent.IWinRTComponentClass + AutoLayout, AnsiClass, Class, ClassSemanticsMask, Abstract, WindowsRuntime + [CompilerGeneratedAttribute] + [GuidAttribute(595258099, 43547, 21940, 123, 11, 53, 220, 245, 117, 190, 210)] + [VersionAttribute(16777216)] + [ExclusiveToAttribute(UnitTestWinRTComponent.WinRTComponent)] + System.Collections.Generic.IList StringList { get; set; } diff --git a/Test/Resources/ExpectedUnprojectedWinRT.txt b/Test/Resources/ExpectedUnprojectedWinRT.txt new file mode 100644 index 0000000..90b4d38 --- /dev/null +++ b/Test/Resources/ExpectedUnprojectedWinRT.txt @@ -0,0 +1,33 @@ + +class + NotPublic + +class UnitTestWinRTComponent.WinRTComponent : System.Object + AutoLayout, AnsiClass, Class, Sealed, SpecialName, BeforeFieldInit + [MarshalingBehaviorAttribute] + [ThreadingAttribute] + [VersionAttribute(16777216)] + [ActivatableAttribute(16777216)] + UnitTestWinRTComponent.IWinRTComponentClass + UnitTestWinRTComponent.WinRTComponent() + System.Collections.Generic.IList StringList { get; set; } + +public class UnitTestWinRTComponent.WinRTComponent : System.Object + AutoLayout, AnsiClass, Class, Public, Sealed, WindowsRuntime, BeforeFieldInit + [MarshalingBehaviorAttribute] + [ThreadingAttribute] + [VersionAttribute(16777216)] + [CompilerGeneratedAttribute] + [ActivatableAttribute(16777216)] + UnitTestWinRTComponent.IWinRTComponentClass + Windows.Foundation.IStringable + UnitTestWinRTComponent.WinRTComponent() + Windows.Foundation.Collections.IVector StringList { get; set; } + +interface UnitTestWinRTComponent.IWinRTComponentClass + AutoLayout, AnsiClass, Class, ClassSemanticsMask, Abstract, WindowsRuntime + [CompilerGeneratedAttribute] + [GuidAttribute(595258099, 43547, 21940, 123, 11, 53, 220, 245, 117, 190, 210)] + [VersionAttribute(16777216)] + [ExclusiveToAttribute(UnitTestWinRTComponent.WinRTComponent)] + Windows.Foundation.Collections.IVector StringList { get; set; } diff --git a/Test/Resources/UnitTestWinRTComponent.winmd b/Test/Resources/UnitTestWinRTComponent.winmd new file mode 100644 index 0000000..ec14676 Binary files /dev/null and b/Test/Resources/UnitTestWinRTComponent.winmd differ diff --git a/Test/UnitTest1.cs b/Test/UnitTest1.cs index 2eafef5..4bb79cf 100644 --- a/Test/UnitTest1.cs +++ b/Test/UnitTest1.cs @@ -17,29 +17,58 @@ static public void Initialize(TestContext context) //_testAssembly = Properties.Resources.TestAssembly; } - Assembly _testAssembly; - + // Load a .Net (not WinRT) assembly using it's name [TestMethod] - public void TestMethod1() + public void TestDotNetAssembly() { + var testAssembly = typeof(UnitTestSampleAssembly.Class1<,,>).Assembly; + var loadContext = new MrLoadContext(); - loadContext.AssemblyPathFromName = AssemblyPathFromName; + loadContext.AssemblyPathFromName = (string assemblyName) => + { + if (testAssembly.GetName().Name == assemblyName) + { + return testAssembly.Location; + } + + return null; + }; + + loadContext.LoadFromAssemblyName(testAssembly.GetName().Name); + loadContext.FinishLoading(); + + TestMethodHelper(loadContext, Properties.Resources.ExpectedOutput); + } + + // Load a WinMD from memory + [TestMethod] + public void TestWinMD() + { + var loadContext = new MrLoadContext(useWinRTProjections: true); + loadContext.LoadAssemblyFromBytes(Properties.Resources.UnitTestWinRTComponent); + loadContext.FinishLoading(); - _testAssembly = typeof(UnitTestSampleAssembly.Class1<,,>).Assembly; + TestMethodHelper(loadContext, Properties.Resources.ExpectdProjectedWinRT); - loadContext.LoadFromAssemblyName(_testAssembly.GetName().Name); + loadContext = new MrLoadContext(useWinRTProjections: false); + loadContext.LoadAssemblyFromBytes(Properties.Resources.UnitTestWinRTComponent); loadContext.FinishLoading(); + TestMethodHelper(loadContext, Properties.Resources.ExpectedUnprojectedWinRT); + } + + public void TestMethodHelper(MrLoadContext loadContext, string expectedOutput) + { Assert.IsTrue(loadContext.LoadedAssemblies.Count() == 1); var testAssembly = loadContext.LoadedAssemblies.First(); var builder = new StringBuilder(); WriteTypes(testAssembly, builder); - Assert.AreEqual(builder.ToString(), Properties.Resources.ExpectedOutput); - + Assert.AreEqual(builder.ToString(), expectedOutput); } + private static void WriteTypes(MrAssembly testAssembly, StringBuilder result) { foreach (var mrType in testAssembly.GetAllTypes()) @@ -119,7 +148,7 @@ private static void WriteTypes(MrAssembly testAssembly, StringBuilder result) MrType itemPropertyType = null; if (propertyName == "Item") { - itemPropertyType = property.GetItemType(publicishOnly:true); + itemPropertyType = property.GetItemType(publicishOnly: true); } if (itemPropertyType == null) @@ -153,9 +182,9 @@ private static void WriteTypes(MrAssembly testAssembly, StringBuilder result) result.AppendLine(")"); } - foreach(var field in mrType.GetFields()) + foreach (var field in mrType.GetFields()) { - if(mrType.IsEnum) + if (mrType.IsEnum) { if (!field.IsSpecialName) // Ignore special value__ field { @@ -203,14 +232,5 @@ private static void WriteParameters(ImmutableArray parameters, Stri } } - private string AssemblyPathFromName(string assemblyName) - { - if(_testAssembly.GetName().Name == assemblyName) - { - return _testAssembly.Location; - } - - return null; - } } } diff --git a/Test/UnitTestWinRTComponent/Properties/AssemblyInfo.cs b/Test/UnitTestWinRTComponent/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0d4da4b --- /dev/null +++ b/Test/UnitTestWinRTComponent/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnitTestWinRTComponent")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTestWinRTComponent")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Test/UnitTestWinRTComponent/UnitTestWinRTComponent.csproj b/Test/UnitTestWinRTComponent/UnitTestWinRTComponent.csproj new file mode 100644 index 0000000..29d9c6f --- /dev/null +++ b/Test/UnitTestWinRTComponent/UnitTestWinRTComponent.csproj @@ -0,0 +1,143 @@ + + + + + Debug + AnyCPU + {95C612FE-E84C-4923-9AB3-CD305B4F5C84} + winmdobj + Properties + UnitTestWinRTComponent + UnitTestWinRTComponent + en-US + UAP + 10.0.19041.0 + 10.0.17763.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + false + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + x86 + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + x86 + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + ARM + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + ARM + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + ARM64 + true + bin\ARM64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + ARM64 + bin\ARM64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + x64 + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + x64 + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + PackageReference + + + + + + + + 6.2.10 + + + + 14.0 + + + + \ No newline at end of file diff --git a/Test/UnitTestWinRTComponent/WinRTComponent.cs b/Test/UnitTestWinRTComponent/WinRTComponent.cs new file mode 100644 index 0000000..dc4fda1 --- /dev/null +++ b/Test/UnitTestWinRTComponent/WinRTComponent.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UnitTestWinRTComponent +{ + public sealed class WinRTComponent + { + public IList StringList { get; set; } + } +} diff --git a/Test/UnitTests.csproj b/Test/UnitTests.csproj index ade4ee4..0fe5b80 100644 --- a/Test/UnitTests.csproj +++ b/Test/UnitTests.csproj @@ -83,6 +83,7 @@ + @@ -98,10 +99,13 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer + + @@ -111,6 +115,10 @@ + + + + \ No newline at end of file diff --git a/Test/packages.config b/Test/packages.config index ac145dc..7ce1881 100644 --- a/Test/packages.config +++ b/Test/packages.config @@ -8,4 +8,6 @@ + + \ No newline at end of file