tags:

views:

63

answers:

3

I added a Script# project to my website project and created a small sample library with two classes.

Now I want to use these classes from the website code. In this case, I created a simple object tree and serialized it to JSON (which would then get fetched by the client-side code).

I tried adding a reference to the Script# project. It compiles fine but then gives me an error when launching about:

  • Assembly not found
  • Runtime version differing

Is it even possible to share code between Script# and ordinary C#?

I am using Script# 0.6 with VS 2010 and .NET 3.5 (both projects).

A: 

Is it even possible to share code between Script# and ordinary C#?

This is not really possible. Your project would have to be in C# 2.0 and would have to conform to Script#'s restrictions. Instead, you can setup an automapper.

For me, I found it easier to setup a second domain model in Script#, I did not have that large of a domain model to begin with.

Keep in mind that Script# simply compiles down to Javascript.

chum of chance
Maybe Script# will get some convenience features in that regard at some point. Though it will probably always lag behind in the runtime version.
A: 

One possible way to share code between script# and c# is to add a link to the source file. In VS you can add a source file to a project as a link when you add it to the project (the file is not copied, but instead, it adds a reference to the source file). In the c# project, the same file is added in the normal way. The result of this is, whenever you change code, these changes will be reflected in both projects. When the file is compiled, the one in the c# project will be compiled with the c# compiler, the one in the script# will be compiled with the script# compiler.

Of course, you would have to be careful to only use features that are common to c# and script#. This limits the possible uses, but maybe data structures could be shared this way.

rekna