Can I use same object in Silverlight 4 project and in a standard ClassLibrary?
I've got this schema:
Silverlight4 project 1a. silverlight class library project with some objects
WebService project 2a. standard 开发者_高级运维class library with logic for WebService
I want to use objects from 1a. also in 2a. but I can't reference it directly in case of different types of frameworks error. What is usual solution here? Made 2a. SilverlightClassLibrary too or what?
I use the functionality "Add as Link".
A simple example:
- Add a class to the Silverlight Library.
- Right mouse button click on the WebService class library -> Add -> Existing Item
- Select the file of the class -> Click on an arrow on the right of the Ok button -> Add As Link.
Also you can reference a class in an opposite direction (from a .NET Class Library to a Sivlerlight one), but in this case a compatibility isn't guaranteed.
It might be overkill for your needs, but you could consider using WCF Ria Services:
WCF RIA Services: Shared Code
WCF RIA Services enables you to write application logic that is shared between the middle tier and the presentation tier.
The above link covers the advantages and disadvantages of sharing files using RIA Services and the linked file approach.
You can't reference assemblies targeting the full .NET Framework in Silverlight, but you can reference Silverlight assemblies in projects targeting the full .NET Framework. So you can define objects to be shared in a Silverlight Class Library project, which both projects reference. This is probably the easiest way. If you want two separate projects that use the same code (such as if you want to include other logic in the project that doesn't apply to Silverlight), then you can use Vortex's solution, but otherwise this way lets you just maintain the one project.
精彩评论