I am trying to create a portable class library that uses implementations from the platform when it is available. For example, Lazy<T> is available in .NET 4.5, Windows Store Apps, Windows Phone 8, but it is not available on Windows Phone 7, Silverlight 4. When my PCL boots onto one of the platforms with the Lazy<T> implementation, I want to use the implementation platforms. When it is not available on the platform, I want to use my own implementation. This seems possible, because Microsoft BCL does it, but I did not understand how to implement it.
I read that with TypeForwardedToAttribute you can redirect PCL to use the implementation from the platform. I'm not quite sure how to set up Visual Studio projects to achieve this result. If CoreLib is my library and ShimLib contains my Lazy<T> implementation. Where can I add TypeForwardedToAttribute? The attribute requires an actual typeof(System.Lazy<>) type description typeof(System.Lazy<>) , which does not work if Windows Phone 7 is targeted in PCL. If I remove Windows Phone 7, I cannot add the link from CoreLib to ShimLib because ShimLib does not support all platforms that CoreLib does. How can I handle this?
Yes, I know that Lazy<T> very simple to implement, but this is just an example, and my actual situation applies to many other classes that are less trivial to implement.
Matt dotson
source share