JsClass Class
The JavaScript class of a .NET class. The source generator derives it for each class marked with JsExportAttribute, and exposes it as the static JsClass property of the class: JsRealm.GetClass creates its constructor and its prototype in a realm.
public abstract class JsClassConstructors
| Name | Description |
|---|---|
| JsClass(string, Type, JsClass?) | Initializes the class. |
JsClass(string, Type, JsClass?)
JsClass.csProperties
| Name | Description |
|---|---|
| BaseClass | Gets the JavaScript class of the nearest base class marked with JsExportAttribute: the prototypes of its constructor and of its prototype. |
| ConstructorLength | Gets the length of the constructor: the number of its required parameters. |
| IsStatic | Gets whether the .NET class is static: its JavaScript value is a plain object whose properties are its static members. |
| Name | Gets the name of the JavaScript class. |
| Type | Gets the .NET class. |
BaseClass
JsClass.csGets the JavaScript class of the nearest base class marked with JsExportAttribute: the prototypes of its constructor and of its prototype.
public JsClass? BaseClass { get; }Property value
ConstructorLength
JsClass.csIsStatic
JsClass.csName
JsClass.csType
JsClass.csMethods
| Name | Description |
|---|---|
| CreateInstance(JsRealm, ReadOnlySpan<JsValue>) | Creates the .NET object of a JavaScript object created by new. |
| DefineAccessor(JsRealm, JsObject, string, JsNativeFunction, JsNativeFunction?) | Defines an accessor as the accessors of a JavaScript class: not enumerable and configurable. |
| DefineMembers(JsRealm, JsObject, JsObject?) | Defines the static members on constructor, and the instance members on prototype. |
| DefineMethod(JsRealm, JsObject, string, int, JsNativeFunction) | Defines a method as the methods of a JavaScript class: writable, not enumerable and configurable. |
| GetArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int) | Converts an argument as JsEngine.ToDotNet does; a missing argument is undefined. A value that cannot be converted to Object (a function, a symbol, a cycle) is a TypeError. |
| GetArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int, T) | Converts an optional argument: defaultValue when it is missing or undefined. |
| GetRequiredArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int) | Converts an argument whose type is a non-nullable reference type: undefined and null throw a TypeError. |
| GetRequiredArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int, T) | Converts an optional argument whose type is a non-nullable reference type: defaultValue when it is missing or undefined, and a TypeError for null. |
| GetThis<T>(JsValue) | Gets the .NET object of the this value of a method. |
CreateInstance(JsRealm, ReadOnlySpan<JsValue>)
JsClass.csCreates the .NET object of a JavaScript object created by new.
protected virtual object? CreateInstance(JsRealm realm, ReadOnlySpan<JsValue> arguments)Parameters
realmJsRealmargumentsReadOnlySpan<JsValue>
Returns
object? The .NET object, or null when the scripts cannot create the class (the constructor throws a TypeError).
DefineAccessor(JsRealm, JsObject, string, JsNativeFunction, JsNativeFunction?)
JsClass.csDefines an accessor as the accessors of a JavaScript class: not enumerable and configurable.
protected static void DefineAccessor(JsRealm realm, JsObject target, string name, JsNativeFunction getter, JsNativeFunction? setter)Parameters
realmJsRealm- The realm of the functions.
targetJsObject- The object that receives the property.
namestring- The name of the property.
getterJsNativeFunction- The getter.
setterJsNativeFunction?- The setter, or null for a read-only property.
DefineMembers(JsRealm, JsObject, JsObject?)
Defines the static members on constructor, and the instance members on prototype.
DefineMethod(JsRealm, JsObject, string, int, JsNativeFunction)
JsClass.csGetArgument overloads
GetArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int)
JsClass.csConverts an argument as JsEngine.ToDotNet does; a missing argument is undefined. A value that cannot be converted to Object (a function, a symbol, a cycle) is a TypeError.
protected static T GetArgument<T>(JsRealm realm, ReadOnlySpan<JsValue> arguments, int index)Type parameters
T
Parameters
realmJsRealmargumentsReadOnlySpan<JsValue>indexint
Returns
T
Exceptions
JsException- The argument cannot be converted (a TypeError or a RangeError).
GetArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int, T)
JsClass.csConverts an optional argument: defaultValue when it is missing or undefined.
protected static T GetArgument<T>(JsRealm realm, ReadOnlySpan<JsValue> arguments, int index, T defaultValue)Type parameters
T
Parameters
realmJsRealmargumentsReadOnlySpan<JsValue>indexintdefaultValueT
Returns
T
Exceptions
JsException- The argument cannot be converted (a TypeError or a RangeError).
GetRequiredArgument overloads
GetRequiredArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int)
JsClass.csConverts an argument whose type is a non-nullable reference type: undefined and null throw a TypeError.
protected static T GetRequiredArgument<T>(JsRealm realm, ReadOnlySpan<JsValue> arguments, int index) where T : classType parameters
T
Parameters
realmJsRealmargumentsReadOnlySpan<JsValue>indexint
Returns
T
Exceptions
JsException- The argument is missing, undefined or null, or it cannot be converted (a TypeError).
GetRequiredArgument<T>(JsRealm, ReadOnlySpan<JsValue>, int, T)
JsClass.csConverts an optional argument whose type is a non-nullable reference type: defaultValue when it is missing or undefined, and a TypeError for null.
protected static T GetRequiredArgument<T>(JsRealm realm, ReadOnlySpan<JsValue> arguments, int index, T defaultValue) where T : classType parameters
T
Parameters
realmJsRealmargumentsReadOnlySpan<JsValue>indexintdefaultValueT
Returns
T
Exceptions
JsException- The argument is null, or it cannot be converted (a TypeError).
GetThis<T>(JsValue)
JsClass.csGets the .NET object of the this value of a method.
protected static T GetThis<T>(JsValue thisValue) where T : classType parameters
T
Parameters
thisValueJsValue
Returns
T
Exceptions
JsException- The value is not an object of the class (a TypeError).