0

I'm writing an HTML parser using SharpKit, which outputs to Javascript; but would also like to run the same code on occasion in CsQuery, which outputs a binary.

The code that I have for SharpKit almost can be directly used in CsQuery, but not quite, as:

  • The namespaces have to be changed, and function/class names changed accordingly.
  • I also have a couple of classes that emulate .NET classes in Sharpkit that I don't need in the CsQuery code at all.

I'd like to be able to do is keep my code synchronized by performing these changes programatically. Is this possible? The solutions here are too old to work with C# 4.0, but I feel like Rosalyn should be able to do this.

4

1 回答 1

0

您可以使用 JsMethodAttribute 重命名 SharpKit 中的方法:

[JsMethod(Name="doSomething")]
public void DoSomething(){}

您可以通过设置 Export=false 以相同的方式排除方法:

[JsMethod(Export=false)]
public void DoSomething(){}

如果您使用 Clr 模式(需要 jsclr.js 库),您应该能够使用完全相同的代码。或者通过使用原生 Js 和 .NET 方法,同时扩展 JavaScript 中缺少的任何方法,例如,如果 JavaScript 没有 String.StartsWith 方法,您可以将其路由到不同的方法,或者使用扩展方法自行实现.

如需更广泛的帮助和代码示例,请尝试 SharpKit 论坛: https ://groups.google.com/forum/#!forum/sharpkit

于 2013-03-21T08:15:33.553 回答