From 8aaa1c7ea1fcceff529f42399121492c5ecf29d9 Mon Sep 17 00:00:00 2001 From: Mike Hillberg <18429489+MikeHillberg@users.noreply.github.com> Date: Tue, 27 Oct 2020 07:23:26 -0700 Subject: [PATCH] Load assemblies from memory, update test to dump fields and item properties --- MiddleweightReflection.sln | 80 +++++++++- MiddleweightReflection/MrLoadContext.cs | 60 ++++++-- Test/Properties/Resources.Designer.cs | 56 +++++++ Test/Properties/Resources.resx | 9 ++ Test/Resources/ExpectdProjectedWinRT.txt | 33 ++++ Test/Resources/ExpectedUnprojectedWinRT.txt | 33 ++++ Test/Resources/UnitTestWinRTComponent.winmd | Bin 0 -> 5632 bytes Test/UnitTest1.cs | 60 +++++--- .../Properties/AssemblyInfo.cs | 29 ++++ .../UnitTestWinRTComponent.csproj | 143 ++++++++++++++++++ Test/UnitTestWinRTComponent/WinRTComponent.cs | 13 ++ Test/UnitTests.csproj | 8 + Test/packages.config | 2 + 13 files changed, 489 insertions(+), 37 deletions(-) create mode 100644 Test/Resources/ExpectdProjectedWinRT.txt create mode 100644 Test/Resources/ExpectedUnprojectedWinRT.txt create mode 100644 Test/Resources/UnitTestWinRTComponent.winmd create mode 100644 Test/UnitTestWinRTComponent/Properties/AssemblyInfo.cs create mode 100644 Test/UnitTestWinRTComponent/UnitTestWinRTComponent.csproj create mode 100644 Test/UnitTestWinRTComponent/WinRTComponent.cs 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 0000000000000000000000000000000000000000..ec14676ebe2e677c3d0dda1f8f06d6098b450370 GIT binary patch literal 5632 zcmeHLYit}>6+W{Mdu`Vn$HZ}xmShqqw28yWaU7JUA@MtQh@HsZI8AERp548+C!XC| zW@i0J0;F|l6(S&2L81?#AOun%q5&#V%A?R9DTTJ8sE7hlnXJ9lQi z>qmCRiPp2(cjSJPzrd1=Yw(jm#Q&v)F<>jTTebal|h;}JK`j-2J zf!u5tXq8%~)WJA7MILu-J>DvMBRWxq!~>q+%qSud+>WCAXpja!&8qyDfBPh}&{o0j zZbll3{?3V*-3E!S1Mg%l(G9a@??$Uckpg)HbVmWLxnjZveT0oeCS&#e1|^$HG^p8* zod6|$YXrgzCF8-{Z;kL?vxR9vk|21sWU54~%ZLISXhmX=*T z>R5wTr){j;xZ!3wf0&Npy$EsFe3Ix(csDZM>)J+o*kP6Dk!a3!&E8(R0EE+1vtw^( zE8bT?H^70KX48s;<_1#PSAD9igo(G5jkMT{cR5IymL9T*u)As?_(UX96^sI!x1ytxIz)kdLz*bUG9p{ym60V_d z0@qMy)qu660&b-3fVWTwU<)MyKPF+Xgttk40&B0)sN^_wC-B1(pTep)O3N*D0(M&H zUSzX{9-xbWUj=NFGbW@oA*Bf^O~_FRsWT<xA(rSidmv2o(b_0Sw@&Ko3zRv`XcgT_^Dg_q0_s%%tS`1+X??i4pu@2m>`48j0v>CA9uOy(dUY=klxpnr5glpM@8>n-a;kbBj z?Xr?tQ*6tfQCho|O(%8Nu+mzWaCM+MrJRIin?{^^CmmO$v=+-WVF)^ownLZmcP>-7;XWu_4 zsY|z=5#5BH*knc!k2FkS%PDnNB%55Ejq$82Xh+s4pjt&dJ3P!5^BPU?cMQSIV8UXb z;TSV`O^zc{adR?exP{|mBeu|!aHYUxPSe(tBBk4-c~MNahlSgY+kqIj3I#dq?Fgh# z*bZ`-AC(ifSm_~SIBUygm@94-PQo@aod3MAZ6aZ29b-(ytUNQHz-BR`j~SMomwDNg zQ}hT^pOBc7m*W1~V6?p#5Om6^1S;gJGSs~FO=W&tB-geTL}lX)Zl5=*{o#0}GM z3#4PZnVnq?nx8H#!F>(VWe z?;YyzTiS5p_|c<>MxGk~TK&oXH!uJ2jt_Mhm)b6cs@jiKZd=jt^%s?imY=S^SpAH$ z^U%*f^O2=X6IVx{3qN$%iZhpgbFTjQn#Wt7d12^e?VY3htIOXyx4kOzPj_>9?LQ72 zxb*CoKe+0~sZQs)jZIhn7P)`({onp*UDTC9?MN8o6lfp9$rkm8#>4f$q)B5!L%%lYRz7FfK`)-&B!8e3J!-HY;^EH>s?xgKaMIdhy}xTd zI<`rxgA>t3(}z;4;bcsGvKwdAGFDfIEL%mT@KsfX8)G=0bTh>B!b9&T1PB_yB8A?# zc&O(3Z#=yBaM`Bwf64y%S48U+S~I`@+N=s>D>VHr#LekX;{lBVeoyS4^aW_`uXwfH{gf1LqE zF3J+3qcdmbjY@<)G>6Z69q6|<5eYl_7uw#%(0yfh$M3z)qEl0&5)xmWj*U5#R z1j-N@aS!R!AI5NIx<&{M-x61~@UP;nF_oX%A>`?u?Aco1bmh$uF{8M*1+y zhUI+R8%Tprt`iMn6Y>`i`_H;*_-Ph+`(EbPXk2=iq9nYE(?R&tfqT0`yI^}*T4t{^ zG$|t;rV-3aGLo4*l}^JimFnRucbuQFQfS9p*(B_yVAsaiPcHies~ppAe-2(*jwzQD zro5H-Z)5A0Yq$sVSco`_^>Yg{NAzCoBSdPDYd6#0>=m57ew*c(CPeSZT*MLSB;x;f X<9NR5rh5M~n%Fwcc^~;d%D}$>o$ttm literal 0 HcmV?d00001 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