-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add markdown readme for System.Reflection.MetadataLoadContext (#70610)
* Create README.md
- Loading branch information
1 parent
7ab7f83
commit 20baea2
Showing
2 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/libraries/System.Reflection.MetadataLoadContext/src/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters