-
Notifications
You must be signed in to change notification settings - Fork 21
Customizing the Generated Output
In general, your C# will translate to Javascript without your having to provide any further info to control the generation process. However, sometimes you will want to customize certain aspects of the generated code. To do this, you annotate your member with [Js(...)]
and pass properties with their own unique characteristics.
-
Export
: Defaults to true. Usage:[Js(Export = false)]
. When specified, the class will be completely omitted from the generated output. This feature is used when you want to map a C# class to an existing Javascript type. For example, this is used to create bindings to jQuery. The method signatures of the jQuery API are surfaced in C# but the references translate directly to jQuery interactions. -
Name
: Overrides the name of the symbol. For classes, fields, properties, methods, etc., this identifier will be used instead of what would otherwise have been generated. This is generally used in conjunction withExport = false
so that a C# identifier can be mapped to a Javascript identifier. The difference often being caused by reasons such as different preferred case-style or forcing overloaded methods to funnel to a common Javascript function. -
Extension
: If true, all invocations to the method or property will be invoked by proxy.method.apply(this, arguments);
This can be useful when creating a stand-in class that represents a built-in type. -
BuiltIn
: When true, the class declaration will not be written out, but all the member declarations will. This allows you to instrument an existing built-in type. -
BaseType
: Forces the class to behave as though it were subclassing this type. This is mostly used for native structs that cannot subclass in C# but where it is desired to inherit behavior from a common type. -
InvokeConstructorAsClass
: Replaces instantiations of this class with invocations of the class as though it were a function. For example, the jQuery class uses this value in conjunction with overriding the name to$
such that instead ofnew jQuery(...)
resolving tonew $(...)
it instead generates$(...)
. This should only be used whenExport = false
.