Migrating from Script#

Saltarelle is intended as an almost drop-in replacement for Script#, with most concepts and library features being similar. There are, however, a few incompatibilities that you will encounter when migrating:

  • Script# uses System.Collections.Dictionary for a simple JS object, whereas Saltarelle uses a type called System.Collections.JsDictionary for the same job (and there are generic counterparts). In Saltarelle, this type does not implement IDictionary (but there is a separate dictionary type that does). This is because the IDictionary interface is broken in Script# (you can’t really implement it).
  • Script# had a [RecordAttribute] (but I think the new method since 0.7 or something to define a record type is to inherit from a class called Record). Saltarelle uses [SerializableAttribute] instead, but inheriting from Record is also a possibility.
  • Script# is very liberal when it comes to not verifying things and casts are compiled to No-ops. Saltarelle will always verify that a value is of the provided type when performing a cast. If you rely on the Script# behaviour you have latent bugs in your code, but you can instruct Saltarelle to ignore the casts by specifying a [ScriptSharpCompatibilityAttribute] with the desired flags on your assembly.
  • In Script#, the char type is a Javascript string, but in Saltarelle it is an integer (closer to the C# semantics). If you have your own methods that use chars, you should verify those. The compiler will give you an error message whenever you try to box a char to an object, because this is likely to have undesired effects (there is a user-defined conversion from char to string that you can insert in these cases).
  • Script# has a Date type, Saltarelle does not have that but instead has DateTime (with the semantics of an immutable struct) and JsDate (with the semantics of a mutable class, equivalent to Script#/Javascript’s Date).
  • To match the Script# semantics for imported generic types and methods, you need to decorate those types/methods with an [IgnoreGenericArguments] attribute.
  • A few methods have been moved/removed. Eg, Script.Alert has been moved to Window. Script.Literal does not exist, but instead you can use dynamic, or define methods decorated with an [InlineCodeAttribute].

If you encounter other issues, please contact me and I will note them here.