问题描述
我添加了一个脚本#项目到我的网站项目,并创建了一个小样本库两大类。
I added a Script# project to my website project and created a small sample library with two classes.
现在我想使用这些类从网站code。在这种情况下,我创建了一个简单的对象树和序列化到JSON(这将随后获得由客户端code获得)。
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:
- 在大会未找到
- 在运行时版本的不同
它甚至有可能共享脚本#和普通的C#的code?
Is it even possible to share code between Script# and ordinary C#?
我使用的脚本#0.6与VS 2010和.NET 3.5(两个项目)。
I am using Script# 0.6 with VS 2010 and .NET 3.5 (both projects).
推荐答案
code是完全共享。我靠,这重用发送的Web服务数据类。
Code is totally sharable. I rely on this for reusing data classes sent over web service.
你可以做的是:
- 设置一个C-尖锐文件调用的文件夹中SharedTypes.cs共享。
- 然后,对于每个项目,右键单击该项目节点,选择添加 - >现有项。浏览SharedTypes.cs,然后单击向下箭头旁边的添加,然后选择添加链接。
- 在那里创建共享类。
- 添加preprocessor符号,比如WEBSERVER,您的服务器端项目。这样,您如果需要有项目之间略有不同的功能。
例如:
public class MyDataPacket
{
public int UserId;
public string SomeData1;
public int SomeData2;
#if SCRIPTSHARP
public MyDataPacket(MyOtherClientSideClass arg)
{
// init
}
#endif
#if WEBSERVER
public MyDataPacket(MyOtherServerSideClass arg)
{
// init
}
#endif
}
编辑:脚本#现在包括一个默认符号 SCRIPTSHARP
,更清晰的意图不是 WEBSERVER
。
Script# now includes a default symbol SCRIPTSHARP
, with clearer intent than !WEBSERVER
.
这篇关于网站/ Web应用程序项目和脚本#/ ScriptSharp之间共享code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!