简体   繁体   中英

Code Generation in a Silverlight WCF RIA Services Project

I have a silverlight 4 project that uses wcf ria services to connect to the server. I have a public class that I need to use on both the client (silverlight) and server. What is the best way to accomplish this?

I have tried using the .shared.cs file convention on the server as well as a linked file (original is on the server). The client thought there was a duplicate class so I changed it to a partial class (I would prefer not to). Then it complained about duplicate properties so I tried the solution to this stack overflow question . The problem I run into using this solution is not being able to access my enumerations that are in the original class on the server.

I also tried a creating a class library project that both of the other projects could reference (silverlight client and server). The problem is finding a type of project to create that both of the projects can reference. Silverlight complains about non silverlight projects and vice versa.

I think the best solution here would be to create a new project in a solution (you may call it Helpers, Common, etc) and add a reference in both client and server projects. That way you will use the same class in both of them and if you change the structure of a class it will affect both projects.

I'm not sure about where your problem came from (what do you mean by not being able to access your enumerations ?) however you may find useful to know that .NET supports a feature called assembly sharing that is meant to share some basic type across silverlight and .net. Just keep in mind that you should reference the Silverlight assembly, not the silverlight project. If this break your compilation order, add also a "fake" project reference into your csproj file like this:

<ProjectReference Include="..\MySilverlightSharedProject.csproj">
  <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>

as documented here

Have you considered using the Portable Library Extension tools .

To quote from here , the Portable Class Library project enables you to write and build managed assemblies that work on more than one .NET Framework platform.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM