Table of Contents

Class Parsers

Namespace
Utils.Objects
Assembly
Utils.dll

Utility class that provides methods to parse strings into various types using reflection and expressions.

public static class Parsers
Inheritance
Parsers
Inherited Members

Methods

CanParse(Type)

Checks if a type can be parsed.

public static bool CanParse(Type type)

Parameters

type Type

The type to check.

Returns

bool

true if the type can be parsed; otherwise, false.

CanParse<T>()

Checks if a type can be parsed.

public static bool CanParse<T>()

Returns

bool

true if the type can be parsed; otherwise, false.

Type Parameters

T

The type to check.

Parse(string, Type)

Converts a string value to the specified type using the current culture.

public static object Parse(string value, Type type)

Parameters

value string

The string value to convert.

type Type

The target type.

Returns

object

The converted value as an object of the specified type.

Parse(string, Type, IEnumerable<IFormatProvider>)

Converts a string value to the specified type using multiple format providers.

public static object Parse(string value, Type type, IEnumerable<IFormatProvider> formatsProviders)

Parameters

value string

The string value to convert.

type Type

The target type.

formatsProviders IEnumerable<IFormatProvider>

An enumerable of format providers to use for conversion.

Returns

object

The converted value as an object of the specified type.

Parse(string, Type, params IFormatProvider[])

Converts a string value to the specified type using multiple format providers.

public static object Parse(string value, Type type, params IFormatProvider[] formatsProviders)

Parameters

value string

The string value to convert.

type Type

The target type.

formatsProviders IFormatProvider[]

An array of format providers to use for conversion.

Returns

object

The converted value as an object of the specified type.

ParseOrDefault<T>(string, IFormatProvider, T)

Parses a string value to a specified type using a format provider, returning a default value if parsing fails.

public static T ParseOrDefault<T>(string value, IFormatProvider formatProvider = null, T defaultValue = default)

Parameters

value string

The string value to parse.

formatProvider IFormatProvider

The format provider to use for parsing.

defaultValue T

The default value to return if parsing fails.

Returns

T

The parsed value of type T or the default value if parsing fails.

Type Parameters

T

The type to parse the value to.

ParseOrDefault<T>(string, IFormatProvider[], T)

Parses a string value to a specified type using multiple format providers, returning a default value if parsing fails.

public static T ParseOrDefault<T>(string value, IFormatProvider[] formatsProviders = null, T defaultValue = default)

Parameters

value string

The string value to parse.

formatsProviders IFormatProvider[]

An array of format providers to use for parsing.

defaultValue T

The default value to return if parsing fails.

Returns

T

The parsed value of type T or the default value if parsing fails.

Type Parameters

T

The type to parse the value to.

ParseOrDefault<T>(string, T)

Parses a string value to a specified type, returning a default value if parsing fails.

public static T ParseOrDefault<T>(string value, T defaultValue = default)

Parameters

value string

The string value to parse.

defaultValue T

The default value to return if parsing fails.

Returns

T

The parsed value of type T or the default value if parsing fails.

Type Parameters

T

The type to parse the value to.

Parse<T>(string)

Parses a string value to a specified type.

public static T Parse<T>(string value)

Parameters

value string

The string value to parse.

Returns

T

The parsed value of type T.

Type Parameters

T

The type to parse the value to.

Parse<T>(string, IEnumerable<IFormatProvider>)

Parses a string value to a specified type using multiple format providers.

public static T Parse<T>(string value, IEnumerable<IFormatProvider> formatsProviders)

Parameters

value string

The string value to parse.

formatsProviders IEnumerable<IFormatProvider>

An enumerable of format providers to use for parsing.

Returns

T

The parsed value of type T.

Type Parameters

T

The type to parse the value to.

Parse<T>(string, params IFormatProvider[])

Parses a string value to a specified type using multiple format providers.

public static T Parse<T>(string value, params IFormatProvider[] formatsProviders)

Parameters

value string

The string value to parse.

formatsProviders IFormatProvider[]

An array of format providers to use for parsing.

Returns

T

The parsed value of type T.

Type Parameters

T

The type to parse the value to.