Renaming
By default, Bootsharp derives JavaScript names from your C# types: a type's namespace becomes the module path, the type name becomes the node (object) under that module, and members are camelCased.
It's possible to customize the behaviour by specifying static methods annotated with [RenameModule], [RenameNode] and [RenameMember] attributes. The methods receive a CLR type associated with the renamed artifact plus the default name generated by Bootsharp and expected to return the custom name you want to use.
Module
[RenameModule] customizes the module path that groups the generated bindings and declarations. The default is the slugified C# namespace, or index for global types. Returning an empty, null or whitespace string falls back to the default index module.
[RenameModule]
public static string RenameModule (Type type, string @default) =>
@default.Replace("/foo/bar", "/foo");In the example above we fold /foo/bar modules into the /foo module.
Node
[RenameNode] customizes the node — the object representing a C# type under its module. The default is the reflected type name. Returning an empty, null or whitespace string erases the type, omitting it from the generated JavaScript.
[RenameNode]
public static string RenameNode (Type type, string @default)
{
if (type.Name == "Foo") return null;
if (type.IsInterface && @default.EndsWith("UI")) return @default[1..^2];
if (type.IsInterface && @default.StartsWith('I')) return @default[1..];
return @default;
}The example removes Foo types from the interop surface, strips the leading I from interface names and drops a trailing UI suffix when present.
Member
[RenameMember] customizes member names — the methods, properties and events projected on an interop surface. The default is the camelCased (and disambiguated) member name. Returning an empty, null or whitespace string erases the member, omitting it from the generated JavaScript.
[RenameMember]
public static string RenameMember (MemberInfo info, string @default)
{
if (info.DeclaringType.Name == "Foo")
if (info is EventInfo) return null;
else return char.ToUpperInvariant(@default[0]) + @default[0..];
return @default;
}Here we drop all events and rename other members declared under Foo to PascalCase.
Combining Renamers
Define any combination of the three renamers — each is optional and resolved independently. The example below groups everything under an api module, removes the interface prefixes and drops properties from all surfaces:
[RenameModule]
public static string Module (Type type, string @default) => "api";
[RenameNode]
public static string Node (Type type, string @default) =>
type.IsInterface ? @default[1..] : @default;
[RenameMember]
public static string Member (MemberInfo info, string @default) =>
info is PropertyInfo ? null : @default;