From 20baea260caf630cdfa723c9ffad792562afe3a5 Mon Sep 17 00:00:00 2001 From: "MSDN.WhiteKnight" <35516665+MSDN-WhiteKnight@users.noreply.github.com> Date: Tue, 21 Jun 2022 11:07:15 +0500 Subject: [PATCH] Add markdown readme for System.Reflection.MetadataLoadContext (#70610) * Create README.md --- .../src/README.md | 40 +++++++++++++++++++ ...stem.Reflection.MetadataLoadContext.csproj | 8 ++-- 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src/libraries/System.Reflection.MetadataLoadContext/src/README.md diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/README.md b/src/libraries/System.Reflection.MetadataLoadContext/src/README.md new file mode 100644 index 0000000000000..d3f1fab8e7f8a --- /dev/null +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/README.md @@ -0,0 +1,40 @@ +## About + +Provides read-only reflection on assemblies in an isolated context with support for assemblies that target different processor architectures and runtimes. Using MetadataLoadContext enables you to inspect assemblies without loading them into the main execution context. Assemblies in MetadataLoadContext are treated only as metadata, that is, you can read information about their members, but cannot execute any code contained in them. + +For more information, see the documentation: + +- [How to: Inspect assembly contents using MetadataLoadContext](https://docs.microsoft.com/dotnet/standard/assembly/inspect-contents-using-metadataloadcontext) +- [System.Reflection.MetadataLoadContext](https://docs.microsoft.com/dotnet/api/system.reflection.metadataloadcontext) +- [System.Reflection.MetadataAssemblyResolver](https://docs.microsoft.com/dotnet/api/system.reflection.metadataassemblyresolver) + +## Example + +The following example shows how print the list of types defined in an assembly. + +```cs +using System; +using System.Reflection; + +class Program +{ + static void Main() + { + string inspectedAssembly = "Example.dll"; + var resolver = new PathAssemblyResolver(new string[] {inspectedAssembly, typeof(object).Assembly.Location}); + using var mlc = new MetadataLoadContext(resolver, typeof(object).Assembly.GetName().ToString()); + + // Load assembly into MetadataLoadContext + Assembly assembly = mlc.LoadFromAssemblyPath(inspectedAssembly); + AssemblyName name = assembly.GetName(); + + // Print types defined in assembly + Console.WriteLine($"{name.Name} has following types: "); + + foreach (Type t in assembly.GetTypes()) + { + Console.WriteLine(t.FullName); + } + } +} +``` diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj b/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj index 94066308f2900..f332e339b8036 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj @@ -4,11 +4,8 @@ System.Reflection true true - Provides read-only reflection on assemblies in an isolated context with support for assemblies that have different architectures and runtimes. - -Commonly Used Types: -System.Reflection.MetadataLoadContext -System.Reflection.MetadataAssemblyResolver + Provides read-only reflection on assemblies in an isolated context with support for assemblies that target different processor architectures and runtimes. Using MetadataLoadContext enables you to inspect assemblies without loading them into the main execution context. Assemblies in MetadataLoadContext are treated only as metadata, that is, you can read information about their members, but cannot execute any code contained in them. + README.md @@ -145,6 +142,7 @@ System.Reflection.MetadataAssemblyResolver +