Table of Contents

Class ValueConverter

Namespace
Ranorex.Core
Assembly
Ranorex.Core.dll

Supports converting strings to various types.

public static class ValueConverter
Inheritance
ValueConverter
Inherited Members

Methods

ArgumentFromString<T>(string, string)

Creates an instance of the specified type from string data.

public static T ArgumentFromString<T>(string argNamename, string value)

Parameters

argNamename string

The name of the argument that the value is being converted for.

value string

The string data representation of the type.

Returns

T

The object instance.

Type Parameters

T

The target type.

Exceptions

Exception

If the value cannot be converted to the specified T.

FromString(string, Type)

Creates an instance of the specified type from string data.

public static object FromString(string value, Type targetType)

Parameters

value string

The string data representation of the type.

targetType Type

The target type to convert to.

Returns

object

The object instance.

Exceptions

ArgumentNullException

If value is null and targetType is a value type or targetType is null.

Exception

If the value cannot be converted to the specified targetType.

FormatException

If the value cannot be parsed and converted to the specified targetType.

FromString<T>(string)

Creates an instance of the specified type from string data.

public static T FromString<T>(string value)

Parameters

value string

The string data representation of the type.

Returns

T

The object instance.

Type Parameters

T

The target type.

Exceptions

Exception

If the value cannot be converted to the specified T.

GetDefaultValue(Type)

Creates a default instance of the specified type.

public static object GetDefaultValue(Type targetType)

Parameters

targetType Type

The target type to create a default instance of.

Returns

object

The default instance or value for the targetType.

Exceptions

ArgumentNullException

If the targetType is null.

RegisterCustomConverter(Type, ValueFromStringDelegate, ValueToStringDelegate)

Registers a custom value converter to use with FromString() and ToString()

public static void RegisterCustomConverter(Type type, ValueFromStringDelegate fromConv, ValueToStringDelegate toConv)

Parameters

type Type

The type to register the converter for.

fromConv ValueFromStringDelegate

The converter delegate for "FromString".

toConv ValueToStringDelegate

The converter delegate for "ToString".

ToDefaultString(Type)

Creates a default string representation of a type.

public static string ToDefaultString(Type targetType)

Parameters

targetType Type

The target type to create from.

Returns

string

The type default value as string.

ToDefaultString(Type, string)

Creates a default string representation of a type.

public static string ToDefaultString(Type targetType, string defaultFormat)

Parameters

targetType Type

The target type to create from.

defaultFormat string

The format to use.

Returns

string

The type default value as string.

ToFriendlyString(object)

Creates a human readable string representation of an object.

public static string ToFriendlyString(object value)

Parameters

value object

The object instance to convert to its human readable string representation.

Returns

string

The object converted to a human readable string.

Remarks

In contrast to Ranorex.Core.ValueConverter.ToString(System.Object,System.String), no base64 encoding is used. Use this method for getting string representations of objects in UIs and RanoreXPaths.

ToString(object)

Creates a string representation of an object.

public static string ToString(object value)

Parameters

value object

The object instance to convert to its string representation.

Returns

string

The object as string.

Remarks

Use this method for storing and loading values (round trip). If the object cannot be converted using the ToFriendlyString(object) method, it is serialized into a base64 string.

TryFromString(string, Type, out object)

Creates an instance of the specified type from string data.

public static bool TryFromString(string value, Type targetType, out object result)

Parameters

value string

The string data representation of the type.

targetType Type

The target type to convert to.

result object

When this method returns, contains the converted object instance.

Returns

bool

If true the value can be converted to the specified targetType.

Exceptions

ArgumentNullException

If value is null and targetType is a value type or targetType is null.

TryFromString<T>(string, out object)

Creates an instance of the specified type from string data.

public static bool TryFromString<T>(string value, out object result)

Parameters

value string

The string data representation of the type.

result object

When this method returns, contains the converted object instance.

Returns

bool

If true the value can be converted to the specified T.

Type Parameters

T

The target type.