在Script#导入库中映射Javascript Mixin的推荐方法是什么?
举个例子:这个qooxdoo api
http://demo.qooxdoo.org/1.5.x/apiviewer/#qx.core.Object
实现此混合
http://demo.qooxdoo.org/1.5.x/apiviewer/#qx.data.MBinding
我应该如何在C#中映射它?扩展方法?接口?
发布于 2011-09-30 21:44:44
如果您查看github上的script#源代码,您将看到在jQuery世界中如何做到这一点的示例。
答案取决于您是简单地尝试导入现有脚本,还是希望使用script#来创作混合本身。
如果您想简单地导入,我建议您查看源代码中的jQuery和jQuery.History项目。jQuery.History表示jQuery历史混合(但没有任何扩展方法或接口)。
如果您想在script#中编写mixin,请继续阅读...高级方法是定义一个静态类,并用Mixin属性对其进行注释。将来,该方法将更改为使用c#扩展方法,但这种自定义方法正是您目前所需要的。
返回到示例-在https://github.com/nikhilk/scriptsharp/blob/master/samples/PhotoDemo/Gallery/GalleryPlugin.cs上,您将看到:
[Mixin("$.fn")]
public static class GalleryPlugin {
public static jQueryObject Gallery(GalleryPluginOptions customOptions) {
...
// Use jQuery.Current to access the "this" object at runtime pointing
// to the object instance whose prototype now contains the mixin methods.
}
}这将生成到脚本中,如下所示:
$.fn.gallery = function(customOptions) {
}作为参考,在开箱即用的jQuery库中定义jQuery.Current的方式(有关完整源代码,请参阅https://github.com/nikhilk/scriptsharp/blob/master/src/Libraries/jQuery/jQuery.Core/jQuery.cs ):
[IgnoreNamespace]
[Imported]
[ScriptName("$")]
public sealed class jQuery {
private jQuery() {
}
[ScriptAlias("this")]
[IntrinsicProperty]
public static jQueryObject Current {
get {
return null;
}
}
}有点复杂,但希望一旦你尝试过,它就会变得简单明了。开箱即用的script#为jQuery场景提供了API和模板,通过删除最前端的机制来帮助简化,当使用不同的脚本框架时,您需要了解这些机制。
希望这能有所帮助!
https://stackoverflow.com/questions/7572888
复制相似问题