Blog speaking .Net C# Javascript, Wordpress

Sharing of source code in Windows and Windows Phone projects

The Portable Class Library (PCL)

The portable Class library (PCL) will allow us to share a large part of the code across projects.

It is possible for a few years to share the PCL code between projects (Sliverlight and WPF, Windows Phone, Windows 8,…).
More projects are different, the more shared classes decreases.

It is important to see that this Library can be used for projects compatible with the selected options.

Note also the visual studio Express editions do not create a PCL, but instead accepts their use in a project.

This Library may use a library which would not have at least the same options selected.

PCL_WindowsMenu

Example of a project Windows 8 and windows Phone.

To simplify our problem we will talk only 2 platforms Windows 8 and Windows Phone. In this example we want to share the code between these multiple platforms (Windows Phone 7, 8, 8.1, Windows 8,…).

In a first approach, a project using a PCL wishing to target all devices could be cut this way

PCL-Sumary

What can you share?

  • (Model) objects and view-models (in a project based in M-V-VM)
  • The data access
  • The navigation used in the MVVM part
  • Resources of type string! Very useful in multilingual projects!

The feedback on a project of this type is as follows. The percentages indicated represent the amount of work done.

PCL-Project_WP

Combine a bit more!

Among several projects, many elements are repeated: the management of image caching, the navigation system, of boxes of dialogues, the http connection / Json, the about… dialog box

As my development I established a common library between my project and that is enriched with each new project. This library allows to avoid rewriting of the code already written but especially reliable the new project with the use of proven code.

PCL-Project_WP_Common

The PCL shared top also has implementations for Windows and Windows Phone platforms

Here for example the structure of 2 of my projects: the project Snowtify and the Armada (WP).

BratchedTools in each of these projects is the shared library.

VisualStudioProjects

In sharing code between projects and between different platforms, so you can hope to reduce the time of your new development about 40%! and migrating to another platform do you that 30% additional cost.

Universals Apps, introduced with Windows Phone 8.1 will go even further by proposing to share the interface between Windows 8 and Windows Phone…

Leave a comment

Your email address will not be published. Required fields are marked *