I'd like to access some internal classes of the .NET Framework, but using reflection is not very readable, and fun to use.
Does somenone know if a tool exists to generate wrapper classes automatically around these internal classes ?
I'd like to access some internal classes of the .NET Framework, but using reflection is not very readable, and fun to use.
Does somenone know if a tool exists to generate wrapper classes automatically around these internal classes ?
Well, Visual Studio can generate wrappers around your own classes for unit testing purposes. This is called shadow classes or shadow assemblies. This can be used to do the same for the framework classes.
There are a few manual steps:
First, create a framework.accessor file, which is a plain text file which should contain the names of the assemblies you would like to have shadows built for (your project must reference the assemblies, also). For instance:
System.dll
Then, manually edit the .csproj file, and add this itemgroup:
<ItemGroup>
<Shadow Include="framework.accessor" />
</ItemGroup>
Build the project. You will now be able to access internal classes and private methods using the generated *_Accessor classes.
Here is a good blog post on the subject (from which I also got most of the information for this answer).
Please remember that using private methods and classes from a library is bad practice, but I assume you have your reasons.