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
Recordis 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.
- Script# has a Date type, Saltarelle does not have that but instead has
DateTime(with the semantics of an immutable struct) and
- To match the Script# semantics for imported generic types and methods, you need to decorate those types/methods with an
- A few methods have been moved/removed. Eg, Script.Alert has been moved to Window.
Script.Literaldoes not exist, but instead you can use dynamic, or define methods decorated with an
If you encounter other issues, please contact me and I will note them here.