You can now add ClearScript attributes to platform and external resources, and more.
ClearScript offers several attributes for controlling how .NET resources are exposed for scripting. They allow hosts to expose type members under substitute names, restrict or block script access to individual resources, and adjust marshaling behavior. An example is
.NET languages typically provide dedicated syntax for declaring attributes in source code, enabling fine-grained customization. However, that approach has some disadvantages:
New attributes can’t be added to code developed elsewhere, such as .NET platform components and external libraries.
There’s no convenient and efficient way to apply attributes broadly – e.g., for automatic renaming of all exposed type members.
Custom Attribute Loaders
ClearScript now funnels all attribute access through a global facility, the custom attribute loader. The host can override that facility to virtualize attribute retrieval, gaining the ability to add new attributes to any .NET resource – as well as modify or hide conventionally declared attributes – all by overriding a single class method.
Example: Expose .NET Type Members as Lower Camel Case
Suppose you’d like to make all exposed .NET type members accessible to script code via lower-camel-cased names. Until now, if your script API included types developed elsewhere, there was no way to achieve this without writing wrappers whose member names were under your control.
Now, by overriding ClearScript’s custom attribute loader, you can write a small method to implement a global transformation to lower camel case:
You can also use this technique to centralize script access control and extend other ClearScript attribute capabilities to platform and external resources.