Skip to content

Commit

Permalink
Add markdown readme for System.Reflection.MetadataLoadContext (#70610)
Browse files Browse the repository at this point in the history
* Create README.md
  • Loading branch information
MSDN-WhiteKnight authored Jun 21, 2022
1 parent 7ab7f83 commit 20baea2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
40 changes: 40 additions & 0 deletions src/libraries/System.Reflection.MetadataLoadContext/src/README.md
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
<RootNamespace>System.Reflection</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>true</IsPackable>
<PackageDescription>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</PackageDescription>
<PackageDescription>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.</PackageDescription>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -145,6 +142,7 @@ System.Reflection.MetadataAssemblyResolver</PackageDescription>
<Compile Include="System\Reflection\TypeLoading\Types\RoType.TypeClassification.cs" />
<Compile Include="System\Reflection\TypeLoading\Types\RoWrappedType.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs" Link="Common\System\Obsoletions.cs" />
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
Expand Down

0 comments on commit 20baea2

Please sign in to comment.