2
votes

I have a Windows Phone 7.1 project with a Portable Class Library targeted to SL4, .Net4.5, WP7.5, Store Apps, but this is not available: http://msdn.microsoft.com/en-us/library/dd642331.aspx

It says it should be available in .Net 4.5. Of course I can program it myself, but I prefer to use functionality provided by the framework.

If I change to Windows Phone 8 (and remove SL4) it is available. Any hacks possible to get it working targeting WP7.5 / SL4?

1

1 Answers

2
votes

You'll need to implement it yourself for WP7.5 and SL4. However, you can make it so that on platforms that already support it (ie .NET 4.5, WP8, etc), it will use the in-box version (and thus you can share it with other libraries that use the "official" version.

Basically, create your implementation as a PCL that targets all the platforms you want. Then create another PCL targeting the platforms that do support System.Lazy. This second library should have the exact same assembly identity as the first one, but instead of having an implementation of the type, it should use the TypeForwardedToAttribute to forward to the existing version of the type.

Then PCLs targeting broader platforms can use the first assembly you created, while platform-specific projects or PCLs targeting narrower platforms can reference the second one. You can make it easy to reference the right version of the assembly from the right projects by packaging them up into a NuGet package.