Class Parsers
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
typeTypeThe type to check.
Returns
CanParse<T>()
Checks if a type can be parsed.
public static bool CanParse<T>()
Returns
Type Parameters
TThe 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
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
valuestringThe string value to convert.
typeTypeThe target type.
formatsProvidersIEnumerable<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
valuestringThe string value to convert.
typeTypeThe target type.
formatsProvidersIFormatProvider[]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
valuestringThe string value to parse.
formatProviderIFormatProviderThe format provider to use for parsing.
defaultValueTThe default value to return if parsing fails.
Returns
- T
The parsed value of type
Tor the default value if parsing fails.
Type Parameters
TThe 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
valuestringThe string value to parse.
formatsProvidersIFormatProvider[]An array of format providers to use for parsing.
defaultValueTThe default value to return if parsing fails.
Returns
- T
The parsed value of type
Tor the default value if parsing fails.
Type Parameters
TThe 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
valuestringThe string value to parse.
defaultValueTThe default value to return if parsing fails.
Returns
- T
The parsed value of type
Tor the default value if parsing fails.
Type Parameters
TThe 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
valuestringThe string value to parse.
Returns
- T
The parsed value of type
T.
Type Parameters
TThe 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
valuestringThe string value to parse.
formatsProvidersIEnumerable<IFormatProvider>An enumerable of format providers to use for parsing.
Returns
- T
The parsed value of type
T.
Type Parameters
TThe 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
valuestringThe string value to parse.
formatsProvidersIFormatProvider[]An array of format providers to use for parsing.
Returns
- T
The parsed value of type
T.
Type Parameters
TThe type to parse the value to.