Unless you explicitly decide not to use helper methods, the HTML Bridge feature automatically supports creating wrappers for managed types that are exposed through either input parameters or return values on scriptable properties, methods, and events.
Only top-level types that are exposed through input parameters or return values are supported. For example, if an input parameter typed as "Customer" has a scriptable property typed as "Address", only "Customer" is automatically exposed. Types for complex subproperties need to be registered explicitly with the HtmlPage..::.RegisterCreateableType method.
The top-level managed reference types must have public default constructors. The constructor does not have to be marked as [ScriptableMemberAttribute]. The reason for this relaxed constraint is that create methods are intended as helper methods for JSON-serializing JavaScript object graphs onto target .NET Framework types. There is no requirement for the target .NET Framework types to be marked as scriptable if they are only used for JSON deserialization targets.
The assemblies that contain top-level types must already be loaded in the target application domain. The HTML Bridge feature will not force the loading of an assembly based on a type that is found in an input parameter or return value.
Types that are List<T>, Dictionary<string,V>, or t[] (array of t) are supported. The specific type of the array or generic parameter is specified by using a mini-language that is supported by the create methods. See the method descriptions later in this topic for syntax information.
Reference types and structures are supported.
If the same base type name is defined in two or more namespaces, and two or more namespace-qualified types are exposed as input parameters or return values of scriptable properties, methods, or events, the type name is not automatically registered. Instead, a developer must explicitly disambiguate the types by using the HtmlPage..::.RegisterCreateableType method.
The following methods are exposed directly off the registered endpoint for a scriptable object.
Return type: jsObject
Parameters: string typeName
Description: Given the typeName of the target .NET Framework type, this method creates a default instance of the type by using either a parameterless constructor (for reference types) or the default value representation (for value types).
The returned object is a JavaScript object that acts as a wrapper for the managed type. If the managed type is not scriptable (that is, it has no scriptable properties, methods, or events), the returned JavaScript object is a black box (that is, it can be passed back into managed code), but there are no scriptable endpoints exposed to JavaScript callers.
For value types, JavaScript receives either a JavaScript primitive value or a JavaScript object that is the result of creating a JSON-serialized representation of the requested .NET Framework type (for example, structures).
The value of typeName must be one of the following:
The name portion of a type. For example, for a type called MyNamespace.Customer, you would use "Customer".
For List<(Of <(T>)>), typeName is "List<T>". For example, to create a List<MyNamespace.Customer>, you would use "List<Customer>".
For Dictionary<string,V>, typeName is "Dictionary<string,V>". For example, to create a Dictionary<string,MyNamespace.Customer>, you would use "Dictionary<string,Customer>". Note that only "Dictionary<string,…>" is supported, because JavaScript has no concept of indexing a dictionary with anything other than string-valued keys.
For arrays of T, typeName is just T[]. For example, to create a Customer[5], you would use ("Customer[]", 5). This also means that for arrays, you always have to use the overload of createManagedObject that has two parameters (see the next section). Otherwise, you will end up with an instance of the requested type instead of an array of instances.
Lists, dictionaries, and arrays can be composed by using this mini-language. For example, to create a List<Dictionary<string,List<Customer[]>>>, you would use "List<Dictionary<string,List<Customer[]>>>".
For types that are specified by using the mini-language, the supplied type string must exactly match the mini-language strings. In other words, the mini-language is case-sensitive.
For types that are specified by using the mini-language, the supplied type string is both space-insensitive and case-insensitive (it uses invariant culture for case comparison). The HTML Bridge feature strips off excess leading and trailing spaces when it parses the type.
The following shorthand C# style type aliases are supported for primitive types. You must use the friendly variations, not the true type names, for these.
int = Int32
byte = Byte
char = Char
bool = Boolean
decimal = Decimal
float = Single
long = Int64
sbyte = SByte
short = Int16
double = Double
string = String
uint = UInt32
ulong = UInt64
ushort = UInt16
If typeName is not in the scope of any top-level types that are used as input parameters or return values on the current script endpoint, the createManagedObject method throws an exception.
If typeName is an unrecognized type string or cannot be parsed, this method throws an exception.
Return type: jsObject
Parameters: string typeName, jsObject initializationData
Description: This method provides the same behavior as createManagedObject(typeName); however, the method JSON-serializes initializationData and then deserializes the resulting JSON string into the target .NET Framework type. In other words, this method is a JSON copy operation from a source JavaScript object graph to a target .NET Framework type.
If the requested typeName is an array, initializationData can instead be an integer that specifies the ordinality of the array.
Since initializationData can only be either a JavaScript object or a number, the second parameter cannot be used to initialize a typeName from the following primitive JavaScript types: number, Boolean, and string. number is interpreted as ordinality for initializing an empty array. Boolean and string are not JavaScript objects, and can be easily represented in JavaScript variables.
If the JSON copy fails, an exception is thrown.