Table of Contents

Class StringEnumValueConverter<T>

Namespace
WebDriverBiDi
Assembly
WebDriverBiDi.dll

Converter for enumerated types that are represented as strings in JSON. This converter supports the use of the StringEnumValueAttribute to specify custom string values for enumerated values, and the StringEnumUnmatchedValueAttribute<T> to specify a default value if the supplied string does not match any of the enumerated values.

public class StringEnumValueConverter<T> where T : struct, Enum

Type Parameters

T

An enumerated type.

Inheritance
StringEnumValueConverter<T>
Inherited Members

Constructors

StringEnumValueConverter()

Initializes a new instance of the StringEnumValueConverter<T> class.

public StringEnumValueConverter()

Properties

NullSentinelValue

Gets the value indicating a null should be serialized in JSON, if any.

public T? NullSentinelValue { get; }

Property Value

T?

Methods

GetString(T)

Gets the string corresponding to the specified enumerated value. If the enumerated value does not match any of the defined values, this method will throw an exception.

public string GetString(T value)

Parameters

value T

The enumerated value.

Returns

string

The string value.

Exceptions

ArgumentException

Thrown when the enumerated value does not match any defined value.

GetValue(string)

Gets the enumerated value corresponding to the specified string. If the string does not match any of the enumerated values, and there is no default value specified, this method will throw an exception.

public T GetValue(string stringValue)

Parameters

stringValue string

The string value to convert.

Returns

T

The enumerated value.

Exceptions

ArgumentException

Thrown when the string value does not match any enumerated value.

TryGetValue(string, out T)

Tries to get the enumerated value corresponding to the specified string.

public bool TryGetValue(string stringValue, out T value)

Parameters

stringValue string

The string value to convert.

value T

The enumerated value.

Returns

bool

true if the string value matches an enumerated value; otherwise, false.