DotNetBrowser  1.14
Public Member Functions | Protected Attributes | Properties | List of all members
DotNetBrowser.JSObject Class Reference

Represents a JavaScript object. Provides access to the object's properties and functions. JavaScript object is alive until its JavaScript execution context exist. Once execution context is disposed, all JavaScript objects available in scope of this context will be automatically disposed. If you try to access already disposed object, you will get InvalidOperationException. More...

Inherits DotNetBrowser.JSValue.

Inherited by DotNetBrowser.JSArray, DotNetBrowser.JSBooleanObject, DotNetBrowser.JSFunction, DotNetBrowser.JSNumberObject, and DotNetBrowser.JSStringObject.

Public Member Functions

bool HasProperty (string name)
 Checks whether JavaScript object has property or function with the given name. More...
 
JSValue GetProperty (string name)
 Returns value of specified JavaScript object's property with the given name. The name parameter represents name of the current JavaScript object property or function. More...
 
bool SetProperty (string name, object value)
 Sets a new property with the given name or modifies existing one in the current JavaScript object and returns true if the property with name was created or updated successfully. The name parameter represents JavaScript object's property name. The value can be one of the following types: String, Boolean, Integer, Long, Short, Byte, Double, Float, Object[], int, boolean, long, short, byte, double, float, Object, JSONString, JSFunctionCallback. More...
 
bool SetProperty (int index, object value)
 Sets a new property with the given index or modifies existing one in the current JavaScript object and returns true if the property with the given index was created or updated successfully. More...
 
bool RemoveProperty (string name)
 Removes property with the given name in the current JavaScript object and returns true if the property was successfully removed. Once you remove key, it will not be available in the current JavaScript object anymore. More...
 
List< string > GetPropertyNames ()
 Returns a list containing the names of the properties of this object, including properties from prototype objects. More...
 
List< string > GetOwnPropertyNames ()
 Returns a list containing the names of the properties of this object, excluding properties from prototype objects. More...
 
override bool IsObject ()
 Indicates whether JavaScript value is an object. If this method returns true, then the value can be casted to JSObject type. For example: More...
 
override bool IsDotNetObject ()
 Indicates whether JavaScript value is an .net object. If this method returns true, then the value can be casted to .net object type. For example: More...
 
override JSObject AsObject ()
 Casts the current JavaScript object to JSObject type. More...
 
override object AsDotNetObject ()
 Casts the current JavaScript object to .net object type. More...
 
string ToJSONString ()
 Returns text representation of JavaScript object. The equivalent of JSON.stringify() without parameters. More...
 
- Public Member Functions inherited from DotNetBrowser.JSValue
virtual bool IsUndefined ()
 Indicates whether JavaScript value is undefined. More...
 
virtual bool IsFunction ()
 Indicates whether JavaScript value is a function. If this method returns true, then the value can be casted to JSFunction type. For example: More...
 
virtual bool IsNull ()
 Indicates whether JavaScript value is NULL. More...
 
bool IsTrue ()
 Indicates whether JavaScript value represents bool TRUE value. More...
 
bool IsFalse ()
 Indicates whether JavaScript value represents bool FALSE value. More...
 
virtual bool IsString ()
 Indicates whether JavaScript value is a string. If this method returns true, then the value can be casted to JSString type. For example: More...
 
virtual bool IsJSON ()
 Indicates whether JavaScript value is a string in JSON format. More...
 
virtual bool IsBool ()
 Indicates whether JavaScript value is a boolean value. If this method returns true, then the value can be casted to JSBoolean type. For example: More...
 
virtual bool IsNumber ()
 Indicates whether JavaScript value is a number value which equals to double type. If this method returns true, then the value can be casted to JSNumber type. For example: More...
 
virtual bool IsArray ()
 Indicates whether JavaScript value is an array. If this method returns true, then the value can be casted to JSArray type. For example: More...
 
virtual bool IsBooleanObject ()
 Indicates whether JavaScript value is a JSBoolean object. If this method returns true, then the value can be casted to JSBooleanObject type. For example: More...
 
virtual bool IsNumberObject ()
 Indicates whether JavaScript value is a Number object. If this method returns true, then the value can be casted to JSNumberObject type. For example: More...
 
virtual bool IsStringObject ()
 Indicates whether JavaScript value is a String object. If this method returns true, then the value can be casted to JSStringObject type. For example: More...
 
virtual JSBoolean AsBoolean ()
 Casts the current JavaScript object to JSBoolean type. If the current object doesn't represent a Boolean object, the InvalidCastException error is thrown. More...
 
virtual JSFunction AsFunction ()
 Casts the current JavaScript object to JSFunction type. If the current object doesn't represent a function, the InvalidCastException error is thrown. More...
 
virtual JSBooleanObject AsBooleanObject ()
 Casts the current JavaScript object to JSBooleanObject type. If the current object doesn't represent a Boolean object, the InvalidCastException error is thrown. More...
 
virtual JSNumber AsNumber ()
 Casts the current JavaScript object to JSNumber type. If the current object doesn't represent a number value, the InvalidCastException error is thrown. More...
 
virtual JSNumberObject AsNumberObject ()
 Casts the current JavaScript object to JSNumberObject type. If the current object doesn't represent a Number object, the InvalidCastException error is thrown. More...
 
virtual JSArray AsArray ()
 Casts the current JavaScript object to JSArray type. If the current object doesn't represent an array, the InvalidCastException error is thrown. More...
 
virtual JSString AsString ()
 Casts the current JavaScript object to JSString type. If the current object doesn't represent a string value, the InvalidCastException error is thrown. More...
 
virtual JSStringObject AsStringObject ()
 Casts the current JavaScript object to JSStringObject type. If the current object doesn't represent a String object, the InvalidCastException error is thrown. More...
 
virtual bool GetBool ()
 Returns boolean value of the current JavaScript object if object represents a primitive boolean or Boolean object, otherwise throws InvalidOperationException. More...
 
virtual double GetNumber ()
 Returns number value of the current JavaScript object if object represents a primitive number or Number object, otherwise throws InvalidOperationException. More...
 
virtual string GetString ()
 Returns string value of the current JavaScript object if object represents a primitive string or String object, otherwise throws InvalidOperationException. More...
 

Protected Attributes

JSContext context
 

Properties

bool IsDisposed [get]
 Indicates whether object is disposed or not. More...
 
JSContext Context [get]
 Gets JavaScript execution context associated with the current JavaScript object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from DotNetBrowser.JSValue
static JSValue Create (double value)
 Creates double JSValue instance. More...
 
static JSValue Create (bool value)
 Creates boolean JSValue instance. More...
 
static JSValue CreateUndefined ()
 Creates undefined JSValue instance. More...
 
static JSValue Create (string value)
 Creates string JSValue instance. More...
 
static JSONString CreateJSON (string jsonString)
 Creates JavaScript value that represents a string in JSON format. When this value is passed to JavaScript side, it will be automatically parsed and converted to appropriate JavaScript object. More...
 
static JSValue CreateNull ()
 Creates null JSValue instance. More...
 

Detailed Description

Represents a JavaScript object. Provides access to the object's properties and functions. JavaScript object is alive until its JavaScript execution context exist. Once execution context is disposed, all JavaScript objects available in scope of this context will be automatically disposed. If you try to access already disposed object, you will get InvalidOperationException.

Member Function Documentation

override object DotNetBrowser.JSObject.AsDotNetObject ( )
virtual

Casts the current JavaScript object to .net object type.

Reimplemented from DotNetBrowser.JSValue.

override JSObject DotNetBrowser.JSObject.AsObject ( )
virtual

Casts the current JavaScript object to JSObject type.

Reimplemented from DotNetBrowser.JSValue.

List<string> DotNetBrowser.JSObject.GetOwnPropertyNames ( )

Returns a list containing the names of the properties of this object, excluding properties from prototype objects.

Returns
a list containing the names of the own properties of this object.
Exceptions
InvalidOperationExceptionwhen object is already disposed or invalid.
JSValue DotNetBrowser.JSObject.GetProperty ( string  name)

Returns value of specified JavaScript object's property with the given name. The name parameter represents name of the current JavaScript object property or function.

Parameters
namestring that represents name of the property or function. Cannot be null or empty.
Returns
value of the JavaScript object's property with the given name. If object doesn't have this key, the return value represent 'undefined' value. See JSValue.IsUndefined().
Exceptions
ArgumentExceptionwhen name is null or empty.
InvalidOperationExceptionwhen object is already disposed or invalid.
List<string> DotNetBrowser.JSObject.GetPropertyNames ( )

Returns a list containing the names of the properties of this object, including properties from prototype objects.

Returns
a list containing the names of the properties of this object.
Exceptions
InvalidOperationExceptionwhen object is already disposed or invalid.
bool DotNetBrowser.JSObject.HasProperty ( string  name)

Checks whether JavaScript object has property or function with the given name.

Parameters
namestring that represents name of the property or function. Cannot be null or empty.
Returns
true if object has property with given name.
Exceptions
ArgumentExceptionwhen name is null or empty.
InvalidOperationExceptionwhen object is already disposed or invalid.
override bool DotNetBrowser.JSObject.IsDotNetObject ( )
virtual

Indicates whether JavaScript value is an .net object. If this method returns true, then the value can be casted to .net object type. For example:

if (value.IsDotNetObject()) { object obj = value.AsDotNetObject(); }

Returns
true when JavaScript value is a .net object.

Reimplemented from DotNetBrowser.JSValue.

override bool DotNetBrowser.JSObject.IsObject ( )
virtual

Indicates whether JavaScript value is an object. If this method returns true, then the value can be casted to JSObject type. For example:

if (value.IsObject()) { JSObject object = value.AsObject(); }

Returns
true when JavaScript value is an object.

Reimplemented from DotNetBrowser.JSValue.

bool DotNetBrowser.JSObject.RemoveProperty ( string  name)

Removes property with the given name in the current JavaScript object and returns true if the property was successfully removed. Once you remove key, it will not be available in the current JavaScript object anymore.

Parameters
namestring that represents name of the property or function. Cannot be null or empty.
Returns
true if the property was successfully removed.
Exceptions
ArgumentExceptionwhen name is null or empty.
InvalidOperationExceptionwhen object is already disposed or invalid.
bool DotNetBrowser.JSObject.SetProperty ( string  name,
object  value 
)

Sets a new property with the given name or modifies existing one in the current JavaScript object and returns true if the property with name was created or updated successfully. The name parameter represents JavaScript object's property name. The value can be one of the following types: String, Boolean, Integer, Long, Short, Byte, Double, Float, Object[], int, boolean, long, short, byte, double, float, Object, JSONString, JSFunctionCallback.

Parameters
namestring that represents name of the property. Cannot be null or empty.
valuea new value associated with the property with the given name. Cannot be null or JSObject with a different JavaScript context.
Returns
true when property with name was created or updated successfully.
Exceptions
ArgumentExceptionwhen name is null or empty.
ArgumentExceptionwhen value is null or represents JSObject with a different JavaScript context.
InvalidOperationExceptionwhen object is already disposed or invalid.
bool DotNetBrowser.JSObject.SetProperty ( int  index,
object  value 
)

Sets a new property with the given index or modifies existing one in the current JavaScript object and returns true if the property with the given index was created or updated successfully.

The index parameter represents JavaScript object's property index. Via the property index you can access its value. The value can be one of the following types: string, int, boolean, long, short, byte, double, float, object, objec[], JSONString, JSFunctionCallback.

As a property value you can set an instance of Object type. In this case the .net object will be automatically converted/wrapped into JavaScript object. You can call .net object's public methods directly from JavaScript code.

Parameters
indexint that represents index of the property.
valuea new value associated with the property with the given index. Cannot be null or JSObject with a different JavaScript context.
Returns
true when property with index was created or updated successfully.
Exceptions
ArgumentExceptionwhen index is negative.
ArgumentExceptionwhen value is null or represents JSObject with a different JavaScript context.
InvalidOperationExceptionwhen object is already disposed or invalid.
string DotNetBrowser.JSObject.ToJSONString ( )

Returns text representation of JavaScript object. The equivalent of JSON.stringify() without parameters.

Returns
a text representation of JavaScript object (including arrays), equivalent to JSON.stringify() output.
Exceptions
InvalidOperationExceptionwhen object has circular fields aka 'obj.field = obj'.
InvalidOperationExceptionwhen object has been already disposed.

Property Documentation

JSContext DotNetBrowser.JSObject.Context
get

Gets JavaScript execution context associated with the current JavaScript object.

bool DotNetBrowser.JSObject.IsDisposed
get

Indicates whether object is disposed or not.