Table of Contents

Class Parsing

Namespace
ArcanaDevelopment.adTempus.Shared
Assembly
ArcanaDevelopment.adTempus.Shared.dll

Methods for parsing values

public static class Parsing
Inheritance
object
Parsing

Methods

ParseBoolean(string)

Parses a bool value from a string

public static bool? ParseBoolean(string strValue)

Parameters

NameTypeDescription
strValue string

Returns

bool?

Remarks

This method recognizes the following values for strValue:

  • true: 1, -1, true, yes, t, y
  • false: 0, false, no, t, n

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

NameTypeDescription
strValue string
defaultValue bool

Returns

bool

Remarks

This method recognizes the following values for strValue:

  • true: 1, -1, true, yes, t, y
  • false: 0, false, no, t, n

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

NameTypeDescription
source string

Returns

DateTime?

The DateTime value parsed from source or null if source cannot 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

NameTypeDescription
source string

Returns

T?

Type Parameters

NameDescription
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

NameTypeDescription
source string
defaultValue T

Returns

T

Type Parameters

NameDescription
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

NameTypeDescription
source string

Returns

int?

The integer value parsed from source or null if source cannot 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

NameTypeDescription
source string
defaultValue int

Returns

int

The integer value parsed from source or defaultValue if source cannot 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

NameTypeDescription
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

NameTypeDescription
strValue string
returnValue bool

Returns

bool

Remarks

This method recognizes the following values for strValue:

  • true: 1, -1, true, yes, t, y
  • false: 0, false, no, t, n

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

NameTypeDescription
source string
value T

Returns

bool

Type Parameters

NameDescription
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

NameTypeDescription
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)