Class Parsing
- Namespace
- ArcanaDevelopment.adTempus.Shared
- Assembly
- ArcanaDevelopment.adTempus.Shared.dll
Methods for parsing values
public static class Parsing
- Inheritance
-
objectParsing
Methods
ParseBoolean(string)
Parses a bool value from a string
public static bool? ParseBoolean(string strValue)
Parameters
| Name | Type | Description |
|---|---|---|
strValue |
string |
Returns
- bool?
Remarks
This method recognizes the following values for strValue:
For all other values it delegates to bool.TryParse(string, out bool)
ParseBoolean(string, bool)
Parses a bool value from a string
public static bool ParseBoolean(string strValue, bool defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
strValue |
string | |
defaultValue |
bool |
Returns
- bool
Remarks
This method recognizes the following values for strValue:
For all other values it delegates to bool.TryParse(string, out bool)
ParseDateTime(string)
Parses a DateTime from a string
public static DateTime? ParseDateTime(string source)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string |
Returns
- DateTime?
The DateTime value parsed from
sourceor null ifsourcecannot be parsed as an integer.
Remarks
This method calls System.DateTime.TryParse(string, out System.DateTime) to perform the parsing.
ParseEnum<T>(string)
Parses an enum value from a string, which may contain either the text or numeric value for the enum.
public static T? ParseEnum<T>(string source) where T : struct, Enum
Parameters
| Name | Type | Description |
|---|---|---|
source |
string |
Returns
- T?
Type Parameters
| Name | Description |
|---|---|
T |
Remarks
For an enum with the Flags attribute the source can specify the value names separated by commas, spaces, or vertical bars (|), e.g.,
"flag1 flag2 flag3"
ParseEnum<T>(string, T)
Parses an enum value from a string, which may contain either the text or numeric value for the enum.
public static T ParseEnum<T>(string source, T defaultValue) where T : struct, Enum
Parameters
| Name | Type | Description |
|---|---|---|
source |
string | |
defaultValue |
T |
Returns
- T
Type Parameters
| Name | Description |
|---|---|
T |
Remarks
For an enum with the Flags attribute the source can specify the value names separated by commas, spaces, or vertical bars (|), e.g.,
"flag1 flag2 flag3"
ParseInt(string)
Parses an int from a string
public static int? ParseInt(string source)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string |
Returns
- int?
The integer value parsed from
sourceor null ifsourcecannot be parsed as an integer.
Remarks
This method calls int.TryParse(string, out int) to perform the parsing.
ParseInt(string, int)
Parses an int from a string
public static int ParseInt(string source, int defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string | |
defaultValue |
int |
Returns
- int
The integer value parsed from
sourceordefaultValueifsourcecannot be parsed as an integer.
Remarks
This method calls int.TryParse(string, out int) to perform the parsing.
ParseVersion(string)
Parses a System.Version from a string
[CanBeNull]
public static Version ParseVersion(string source)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string |
Returns
- Version
Remarks
Unlike System.Version.Parse(string), this method sets missing version parts to 0 rather than -1. For example source="4.1" will return new Version(4,1,0,0)
rather than new Version(4,1,-1,-1)
If source is not a valid version, returns null.
TryParseBoolean(string, out bool)
Parses a bool value from a string
public static bool TryParseBoolean(string strValue, out bool returnValue)
Parameters
| Name | Type | Description |
|---|---|---|
strValue |
string | |
returnValue |
bool |
Returns
- bool
Remarks
This method recognizes the following values for strValue:
For all other values it delegates to bool.TryParse(string, out bool)
TryParseEnum<T>(string, out T)
Parses an enum value from a string, which may contain either the text or numeric value for the enum.
public static bool TryParseEnum<T>(string source, out T value) where T : struct, Enum
Parameters
| Name | Type | Description |
|---|---|---|
source |
string | |
value |
T |
Returns
- bool
Type Parameters
| Name | Description |
|---|---|
T |
Remarks
For an enum with the Flags attribute the source can specify the value names separated by commas, spaces, or vertical bars (|), e.g.,
"flag1 flag2 flag3"
TryParseVersion(string, out Version)
Parses a System.Version from a string
public static bool TryParseVersion(string source, out Version version)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string | |
version |
Version |
Returns
- bool
Remarks
Unlike System.Version.Parse(string), this method sets missing version parts to 0 rather than -1. For example source="4.1" will return new Version(4,1,0,0)
rather than new Version(4,1,-1,-1)