JsPropertyKey Struct

A property key: a string or a symbol (https://tc39.es/ecma262/#sec-object-type).

public readonly struct JsPropertyKey : IEquatable<JsPropertyKey>
Implements

Constructors

NameDescription
JsPropertyKey(JsSymbol)Creates a symbol key.
JsPropertyKey(string)Creates a string key.

JsPropertyKey overloads

JsPropertyKey(JsSymbol)

JsPropertyKey.cs

Creates a symbol key.

public JsPropertyKey(JsSymbol symbol)
Parameters
symbol JsSymbol

JsPropertyKey(string)

JsPropertyKey.cs

Creates a string key.

public JsPropertyKey(string name)
Parameters
name string

Properties

NameDescription
IsStringGets whether the key is a string.
IsSymbolGets whether the key is a symbol.

Gets whether the key is a string.

public bool IsString { get; }

Property value

bool

Gets whether the key is a symbol.

public bool IsSymbol { get; }

Property value

bool

Methods

NameDescription
AsString()Gets the string of a string key.
AsSymbol()Gets the symbol of a symbol key.
Equals(JsPropertyKey)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Indicates whether this instance and a specified object are equal.
FromValue(JsValue)Creates a key from a string or a symbol value, without running code.
GetHashCode()Returns the hash code for this instance.
ToJsValue()Gets the key as a JavaScript value (a string or a symbol).
ToString()Returns the fully qualified type name of this instance.
TryGetArrayIndex(uint)Gets whether the key is an array index (https://tc39.es/ecma262/#array-index): the canonical string of an integer below 2^32 - 1.

Gets the string of a string key.

public string AsString()

Returns

string

Gets the symbol of a symbol key.

public JsSymbol AsSymbol()

Returns

JsSymbol

Equals overloads

Equals(JsPropertyKey)

JsPropertyKey.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(JsPropertyKey other)
Parameters
other JsPropertyKey
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

JsPropertyKey.cs

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

FromValue(JsValue)

JsPropertyKey.cs

Creates a key from a string or a symbol value, without running code.

public static JsPropertyKey FromValue(JsValue value)

Parameters

value JsValue

Returns

JsPropertyKey

Exceptions

ArgumentException
The value is not a string nor a symbol.

GetHashCode()

JsPropertyKey.cs

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

ToJsValue()

JsPropertyKey.cs

Gets the key as a JavaScript value (a string or a symbol).

public JsValue ToJsValue()

Returns

JsValue

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string The fully qualified type name.

TryGetArrayIndex(uint)

JsPropertyKey.cs

Gets whether the key is an array index (https://tc39.es/ecma262/#array-index): the canonical string of an integer below 2^32 - 1.

public bool TryGetArrayIndex(out uint index)

Parameters

index uint
The index, when the key is an array index.

Returns

bool

Operators

NameDescription
operator ==(JsPropertyKey, JsPropertyKey)Compares two keys.
implicit operator JsPropertyKey(JsSymbol)Creates a symbol key.
implicit operator JsPropertyKey(string)Creates a string key.
operator !=(JsPropertyKey, JsPropertyKey)Compares two keys.

operator ==(JsPropertyKey, JsPropertyKey)

JsPropertyKey.cs

Compares two keys.

public static bool operator ==(JsPropertyKey left, JsPropertyKey right)

Parameters

left JsPropertyKey
right JsPropertyKey

Returns

bool

op_Implicit overloads

implicit operator JsPropertyKey(JsSymbol)

JsPropertyKey.cs

Creates a symbol key.

public static implicit operator JsPropertyKey(JsSymbol symbol)
Parameters
symbol JsSymbol
Returns

JsPropertyKey

implicit operator JsPropertyKey(string)

JsPropertyKey.cs

Creates a string key.

public static implicit operator JsPropertyKey(string name)
Parameters
name string
Returns

JsPropertyKey

operator !=(JsPropertyKey, JsPropertyKey)

JsPropertyKey.cs

Compares two keys.

public static bool operator !=(JsPropertyKey left, JsPropertyKey right)

Parameters

left JsPropertyKey
right JsPropertyKey

Returns

bool