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 markdown readme for System.Reflection.MetadataLoadContext #70610

Merged
merged 3 commits into from
Jun 21, 2022
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
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