Class ValueConverter
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
argNamenamestringThe name of the argument that the value is being converted for.
valuestringThe string data representation of the type.
Returns
- T
The object instance.
Type Parameters
TThe target type.
Exceptions
- Exception
If the
valuecannot be converted to the specifiedT.
FromString(string, Type)
Creates an instance of the specified type from string data.
public static object FromString(string value, Type targetType)
Parameters
valuestringThe string data representation of the type.
targetTypeTypeThe target type to convert to.
Returns
- object
The object instance.
Exceptions
- ArgumentNullException
If
valueisnullandtargetTypeis a value type ortargetTypeisnull.- Exception
If the
valuecannot be converted to the specifiedtargetType.- FormatException
If the
valuecannot be parsed and converted to the specifiedtargetType.
FromString<T>(string)
Creates an instance of the specified type from string data.
public static T FromString<T>(string value)
Parameters
valuestringThe string data representation of the type.
Returns
- T
The object instance.
Type Parameters
TThe target type.
Exceptions
- Exception
If the
valuecannot be converted to the specifiedT.
GetDefaultValue(Type)
Creates a default instance of the specified type.
public static object GetDefaultValue(Type targetType)
Parameters
targetTypeTypeThe target type to create a default instance of.
Returns
- object
The default instance or value for the
targetType.
Exceptions
- ArgumentNullException
If the
targetTypeisnull.
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
typeTypeThe type to register the converter for.
fromConvValueFromStringDelegateThe converter delegate for "FromString".
toConvValueToStringDelegateThe converter delegate for "ToString".
ToDefaultString(Type)
Creates a default string representation of a type.
public static string ToDefaultString(Type targetType)
Parameters
targetTypeTypeThe 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
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
valueobjectThe 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
valueobjectThe 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
valuestringThe string data representation of the type.
targetTypeTypeThe target type to convert to.
resultobjectWhen this method returns, contains the converted object instance.
Returns
- bool
If
truethevaluecan be converted to the specifiedtargetType.
Exceptions
- ArgumentNullException
If
valueisnullandtargetTypeis a value type ortargetTypeisnull.
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
valuestringThe string data representation of the type.
resultobjectWhen this method returns, contains the converted object instance.
Returns
- bool
If
truethevaluecan be converted to the specifiedT.
Type Parameters
TThe target type.