R.D
R.D

Reputation: 4871

How to use Same Library for Silverlight and CLR

I Have a library which has custom domain logic. Some of the stuff is heavy hitting and depend on the core runtime outside silverlight runtime.

Is it possible to compile the same code for 2 different runtimes and reference different flavours from different consumers? How

Upvotes: 3

Views: 260

Answers (4)

Jarek Kardas
Jarek Kardas

Reputation: 8455

There are several ways to achieve what you want.

  1. You cannot reference full .net framework assemblies in silverlight, but you can do it the other way round, so you can code against SL and then reference SL projects in projects compiled against full .Net.

  2. You can add files from other projects as links to share source code instead of referencing assemblies

  3. Even better, you can use Prism v2 and Project Linker addin that comes with it to let Visual Studio manage files linking between projects. You can read more about multi-platform targeting here

Upvotes: 3

GregC
GregC

Reputation: 8007

Have you considered using Workflow Foundation for your task?

P.S. The question is VERY broad. Could you supply a sample so we have something to work with?

Upvotes: 1

AndrewS
AndrewS

Reputation: 3510

A simple, high level answer is that you put your common code in an assembly that both CLR and Silverlight assemblies reference. Anything that is specific to either platform must be abstracted out of the common code and implemented in the CLR and Silverlight projects.

Behold the wonders of inheritance and polymorphism ;)

[On a side note: if you find yourself copy-pasting code (either snippets or whole cs files), you're doing something very wrong]

Upvotes: 2

Nate
Nate

Reputation: 30656

Add two class library projects (SLLib, CLRLib) to your solution. Then add all your .cs files to both solutions.

Upvotes: 0

Related Questions