Search code examples
c#windows-phone-8reusability

Code reuse Windows Phone 8


I am working in a project targeting Windows Phone 8. What is the best approach to reuse code from this project? The goal is to reproduce similar projects that will have common ui and functionality. I want to change some colors, some translations and a bit of the logic. Is possible to change only some parts of my project? From the web search I found many resources of how to reuse code and target multiple platforms (Windows 8, Windows Phone 8, etc). My use case is a little different. I have already a project and want multiple copies with small changes and the main logic in common.


Solution

  • Extract your logic into other project(s).

    1. Create a new Class Library project.

    Two files will be created: a default class file Class1.cs and the assembly manifest AssemblyInfo.cs, which contains metadata about the code library.

    2. If you want to write or move code to your library:

    From the Project menu, choose Add New Item to add the appropriate new item (control, component, class, and so on) and then move/write the appropriate code.

    3. Reference the newly created library to your projects.

    In references menu of your WP8 projects select Add new reference and choose the newly created library.