C# to JavaScript compiler

# Attribute Reference

h5 provides a rich set of attributes to control compilation, interoperability, and output generation.

# Compilation Control

# [FileName]

Specifies the output file name for a class or assembly.

[FileName("my-file.js")]
public class MyClass { }

# [Module]

Defines the module system or module name for a class or assembly.

[Module(ModuleType.CommonJS)]
public class MyModule { }

[Module("react")]
public class ReactInterop { }

# [Reflectable]

Controls reflection metadata generation.

[Reflectable(false)]
public class NonReflectable { }

# [NonScriptable]

Excludes a member from being emitted to JavaScript.

[NonScriptable]
public void HelperMethod() { }

# Initialization

# [Ready]

Marks a method to run when the DOM is ready.

[Ready]
public static void OnReady() { }

# [Init]

Marks a method to run immediately upon script loading.

[Init]
public static void Initialize() { }

# Interoperability

# [External]

Marks a class or member as existing externally (no implementation generated).

[External]
public class ExistingJsLibrary { }

# [Template]

Defines a custom JavaScript template for a method call.

[Template("console.log({0})")]
public static extern void Log(object message);

# [Script]

Injects raw JavaScript into the method body.

[Script("alert('Hello');")]
public void Alert() { }

# [GlobalTarget]

Compiles the class members as global functions/variables.

[GlobalTarget("window")]
public static class WindowExtensions { }

# [ObjectLiteral]

Compiles the class as a plain JavaScript object literal.

[ObjectLiteral]
public class Options { public int Id { get; set; } }

# [Enum]

Controls how enums are emitted (as numbers or strings).

[Enum(Emit.StringName)]
public enum Color { Red, Green }

# Naming & Structure

# [Name]

Overrides the name of a class, method, property, or field in the generated JavaScript.

[Name("myCustomName")]
public void MyMethod() { }

# [Namespace]

Overrides the namespace or disables namespace generation.

[Namespace("My.Custom.Namespace")]
public class MyClass { }

[Namespace(false)] // No namespace prefix
public class GlobalClass { }

# [Convention]

Applies naming conventions (e.g., camelCase) to members.

[Convention(Notation.CamelCase)]
public class MyClass { }

# Type System

# [Cast]

Customizes the implementation of a cast operation.

[Cast("Number({0})")]
public static extern int ToInt(object value);

# [IgnoreCast]

Disables runtime type checks and conversions for a cast.

[IgnoreCast]
public T As<T>() { return (T)(object)this; }