JSMarshaller class
Generates expressions and delegates that support marshaling between .NET and JS.
C#
public class JSMarshaller
Public Members
name | description |
---|---|
JSMarshaller() | The default constructor. |
static Current { get; } | |
AutoCamelCase { get; set; } | Gets or sets a value indicating whether the marshaller automatically converts casing between TitleCase .NET member names and camelCase JavaScript member names. |
BuildConstructorOverloadDescriptorExpression(…) | Builds a lambda expression that generates a callback descriptor that resolves and invokes the best-matching overload from a set of overloaded constructors. |
BuildFromJSConstructorExpression(…) | Builds a lambda expression for a JS callback adapter that constructs an instance of a .NET class or struct. When invoked, the expression will marshal the constructor arguments from JS, invoke the constructor, then return the new instance either as a wrapped .NET class or a JS object marshalled from the struct. |
BuildFromJSFunctionExpression(…) | Builds a lambda expression for a .NET adapter from a JS function that calls a .NET delegate. When invoked, the adapter will marshal the arguments from JS, invoke the .NET delegate, then marshal the return value (or exception) back to JS. |
BuildFromJSMethodExpression(…) | Builds a lambda expression for a JS callback adapter to a .NET method. When invoked, the expression will marshal the arguments from JS, invoke the method, then marshal the return value (or exception) back to JS. |
BuildFromJSPropertyGetExpression(…) | Builds a lambda expression for a JS callback adapter to a .NET property getter. When invoked, the expression will get the property value and marshal it back to JS. |
BuildFromJSPropertySetExpression(…) | Builds a lambda expression for a JS callback adapter to a .NET property setter. When invoked, the delegate will marshal the value from JS and set the property. |
BuildMethodOverloadDescriptorExpression(…) | Builds a lambda expression that generates a callback descriptor that resolves and invokes the best-matching overload from a set of overloaded methods. |
BuildToJSFunctionExpression(…) | Builds a lambda expression for a .NET adapter to a JS function that is callable as a .NET delegate. When invoked, the adapter will marshal the arguments to JS, invoke the JS function, then marshal the return value (or exception) back to .NET. |
BuildToJSMethodExpression(…) | Builds a lambda expression for a .NET adapter to a JS method. When invoked, the delegate will marshal the arguments to JS, invoke the method on the JS class or instance, then marshal the return value (or exception) back to .NET. |
BuildToJSPropertyGetExpression(…) | Builds a lambda expression for a .NET adapter to a JS property getter. When invoked, the delegate will get the property value from the JS class or instance, marshal the value from JS, and return it. |
BuildToJSPropertySetExpression(…) | Builds a lambda expression for a .NET adapter to a JS property setter. When invoked, the delegate will marshal the value to JS and set the property on the JS class or instance. |
FromJS(…) | Converts from a JS value to a specified type. |
FromJS<T>(…) | Converts from a JS value to a specified type. |
GetConstructorOverloads(…) | Gets overload information for a set of constructors. |
GetFromJSValueDelegate(…) | Gets a delegate that converts from a JS value to a specified type. |
GetFromJSValueDelegate<T>() | Gets a delegate that converts from a JS value to a specified type. |
GetFromJSValueExpression(…) | Gets a lambda expression that converts from a JS value to a specified type. |
GetMethodOverloads(…) | Gets overload information for a set of overloaded methods. |
GetToJSMethodDelegate(…) | Gets a delegate for a .NET adapter to a JS method. When invoked, the adapter will marshal the arguments to JS, invoke the JS method, then marshal the return value (or exception) back to .NET. |
GetToJSValueDelegate(…) | Gets a delegate that converts from a specified type to a JS value. |
GetToJSValueDelegate<T>() | Gets a delegate that converts from a specified type to a JS value. |
GetToJSValueExpression(…) | Gets a lambda expression that converts from a specified type to a JS value. |
MakeInterfaceExpression(…) | Converts a lambda expression that takes a JSValue as the first parameter to a lambda expression that references the member value of a JSInterface and automatically switches to the JS thread. |
ToJS(…) | Converts from a specified type to a JS value. |
ToJS<T>(…) | Converts from a specified type to a JS value. |
const OutParameterPrefix | Prefix applied to the name of out parameters when building expressions. Expressions do not distinguish between ref and out parameters, but the source generator needs to use the correct keyword. |
const ResultPropertyName | When a method has ref and/or out parameters, the results are returned as an object with properties for each of the ref /out parameters along with a result property for the actual return value (if not void). |
static StaticGetToJSMethodDelegate(…) | Gets a delegate for a .NET adapter to a JS method, using the current thread JS marshaller instance. |
static ToCamelCase(…) |
Remarks
Most marshaling logic is generated in the form of lambda expressions. The expressions can then be compiled into delegates at runtime, or written out as source code by a compile time source-generator to support faster startup and AOT compiled binaries.
All methods on this class are thread-safe.