是否可以用C#编写代码并使用Script#在.NET程序集和JavaScript之间共享代码? [英] Is it possible to write code in C# and use Script# to share it between .NET assemblies and JavaScript?
问题描述
我正在研究使用Script#通过将其编译为JavaScript与客户端共享一些C#业务逻辑.
I'm investigating using Script# to share some of our C# business logic with the client-side by compiling it to JavaScript.
问题是,是否可以从另一个.NET程序集中引用Script#类库?我已经尝试通过快速测试和
Question is, is it possible to reference a Script# class library from another .NET assembly? I've tried doing it in a quick test and failed miserably.
浏览Script#源代码使我相信这是不可能的,因为没有为Script#的mscorlib类提供实现代码. 以String类为例.
Looking through the Script# source code leads me to believe this won't be possible because no implementation code has been provided for Script#'s mscorlib classes. See the String class as an example.
如果有人可以提供一个明确的答案,我将非常感激.
If someone can provide a definitive answer on this, I would be very grateful.
推荐答案
我要做的是创建两个项目. #script项目和.net类库项目.然后,我链接每个.cs文件(添加已链接的现有项目).
What I do is to create two projects. The #script proyect and the .net class library proyect. Then I link each of the .cs files (Adding existing items as linked).
您可以使用#IF SCRIPTSHARP .... #ENDIF预处理程序来避免编译特定的#script属性.
You can use #IF SCRIPTSHARP .... #ENDIF preprocesors to avoid compiling specific #script attributes.
最后,您可以编译两个库并重用代码.
Finally you can compile both libraries and reuse the code.
我每天都在使用它,并且效果很好.
I use it every day and it work perfectly well.
这篇关于是否可以用C#编写代码并使用Script#在.NET程序集和JavaScript之间共享代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!