QueryStringConverter.ConvertStringToValue Method (String, Type)


Converts a query string parameter to the specified type.

Namespace:   System.ServiceModel.Dispatcher
Assembly:  System.ServiceModel.Web (in System.ServiceModel.Web.dll)

public virtual object ConvertStringToValue(
	string parameter,
	Type parameterType


Type: System.String

The string form of the parameter and value.

Type: System.Type

The Type to convert the parameter to.

Return Value

Type: System.Object

The converted parameter.

Exception Condition

The provided string does not have the correct format.

If the parameterType is a value type and the parameter is null, then the default value of the parameterType is returned.

The following code shows how to convert a string to the specified type.

if (converter.CanConvert(typeof(Int32)))
    converter.ConvertStringToValue("123", typeof(Int32));

.NET Framework
Available since 3.5
Return to top