Skip to content

Why special Shim types?

Anders Gustafsson edited this page Apr 15, 2015 · 2 revisions

The Shim class library contains a few special classes,

These classes have been added to Shim because the different portable class library profiles contain partial implementations of the Assembly, Path and Environment classes, respectively.

Some static methods and properties are not implemented in the PCL profiles of these classes. Static methods and classes cannot be simulated with extension methods, and since the class in question is already present in the PCL profile, it is also not possible to include a class with the same full name in the Shim library.

To circumvent this issue to the largest possible extent, I have instead implemented an accomanying Shim... class that contains the static methods and properties missing from the PCL implementation.

But this also means that the code that is consuming the Shim library has to be modified, albeit minimally.

If a file of source code that is invoking any of the Assembly, Path or Environment methods or properties missing in PCL, and if the file does not contain any calls to methods or properties in the same class that are contained in PCL, then the redirection can be solved with a using directive in the beginning of the source code file, e.g.

using Assembly = System.Reflection.Assembly;

If, on the other hand, the file of source code contains a mixture of calls, existing and non-existing in PCL, to static methods or properties of the Assembly, Path or Environment classes, it will be necessary to modify the individual lines of source code invoking the methods/properties that are non-existent in PCL, for example:

var assembly = ShimAssembly.GetExecutingAssembly();
var machineName = ShimEnvironment.MachineName;

NOTE! In the upcoming version 2 the Shim prefix will be replaced with a _ suffix. For more information, see discussion at issue #16.

Contribute to continued Shim development!

€10
€25
€50
Clone this wiki locally