jeudi 4 novembre 2021

How to programmatically find and follow forwarded types?

I'm trying to understand how to find and follow Types that are marked for forwarding.

For example, System.IO doesn't contain 'File', it's forwarded to System.IO.FileSystem.

The reason is that I'm using the Razor engine to compile some custom templates, so I need to inject the assemblies as simply including System.IO results in the following:

Unable to compile template: template.cshtml(46,9): error CS1069: The type name 'File' could not be found in the namespace 'System.IO'. This type has been forwarded to assembly 'System.IO.FileSystem, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

Loading the System.IO assembly, GetForwardedTypes() doesn't return 'File'. (it does return things like Stream, TextReader, etc)

The TypeForwardedToAttribute doesn't appear in the assembly.GetCustomAttributes().

I'm struggling to find anything relating to 'File' in the System.IO Assembly object.

So how do I programmatically understand that 'System.IO.File' forwards to 'System.IO.FileSystem'?

What do I do from here?

var assembly = Assembly.Load("System.IO");




Aucun commentaire:

Enregistrer un commentaire