Table of Contents

Class CAToNumber

Namespace
SunamoBts
Assembly
SunamoBts.dll

Collection Array To Number - utilities for converting collections and arrays to numeric types.

public class CAToNumber
Inheritance
CAToNumber
Inherited Members
Extension Methods

Methods

ToIntTruncating(List<string>)

Converts a list of strings to a list of integers, truncating decimal parts. If you need to return null when something doesn't fit, use ToIntWithLengthValidation(IList, int) or ToIntWithLengthValidationAndOffset(IList, int, int).

public static List<int> ToIntTruncating(List<string> list)

Parameters

list List<string>

The list of string values to convert.

Returns

List<int>

A list of integers parsed from the string values.

ToIntWithLengthValidation(IList, int)

Converts an IList to a list of integers with a required length validation.

public static List<int>? ToIntWithLengthValidation(IList list, int requiredLength)

Parameters

list IList

The list to convert.

requiredLength int

The required length of the list.

Returns

List<int>

A list of integers if successful and length matches; otherwise, null.

ToIntWithLengthValidationAndOffset(IList, int, int)

Converts an IList to a list of integers with required length validation and starting offset.

public static List<int>? ToIntWithLengthValidationAndOffset(IList list, int requiredLength, int startFrom)

Parameters

list IList

The list to convert.

requiredLength int

The required length of the result list.

startFrom int

The starting index offset to begin parsing from.

Returns

List<int>

A list of integers if successful and length matches; otherwise, null.

ToNumber<T>(Func<string, T, T>, IList, int)

Converts an IList to a list of T numbers with required length validation. If the list does not have the required length or an element cannot be parsed to T, returns null.

public static List<T>? ToNumber<T>(Func<string, T, T> parseMethod, IList list, int requiredLength)

Parameters

parseMethod Func<string, T, T>

The function to parse each element to type T.

list IList

The list of elements to parse.

requiredLength int

The required length of the result list.

Returns

List<T>

A list of parsed numbers if successful and length matches; otherwise, null.

Type Parameters

T

The target numeric type.

ToNumber<T>(Func<string, T, T>, IList, int, T)

Converts an IList to a list of T numbers with required length validation and a starting offset. If an element in the list cannot be parsed to T, returns null.

public static List<T>? ToNumber<T>(Func<string, T, T> parseMethod, IList list, int requiredLength, T startFrom) where T : IComparable

Parameters

parseMethod Func<string, T, T>

The function to parse each element to type T.

list IList

The list of elements to parse.

requiredLength int

The required minimum length of the result list.

startFrom T

The starting offset to begin parsing from.

Returns

List<T>

A list of parsed numbers if successful; otherwise, null.

Type Parameters

T

The target numeric type that implements IComparable.

ToNumber<T>(Func<string, T, T>, IList, T, bool)

Converts an IList to a list of T numbers using a parse method with a default value. Default value will be used when a parsed element is not a number to return a recognizable bad value.

public static List<T> ToNumber<T>(Func<string, T, T> parseMethod, IList list, T defaultValue, bool isRequiringAllNumbers = true)

Parameters

parseMethod Func<string, T, T>

The function to parse each element to type T.

list IList

The list of elements to parse.

defaultValue T

The default value to use when parsing fails.

isRequiringAllNumbers bool

If true, returns null when any element cannot be parsed.

Returns

List<T>

A list of parsed numbers, or null if a required element cannot be parsed.

Type Parameters

T

The target numeric type.

ToNumber<T, U>(Func<string, T>, IList<U>)

Converts a generic IList to a list of T numbers using a simple parse function. For use with requireAllNumbers, must use other parse func than default .NET.

public static List<T> ToNumber<T, U>(Func<string, T> parseMethod, IList<U> list)

Parameters

parseMethod Func<string, T>

The function to parse each element to type T.

list IList<U>

The list of elements to parse.

Returns

List<T>

A list of parsed numbers, skipping elements that are "NA" or cannot be parsed.

Type Parameters

T

The target numeric type.

U

The type of elements in the source list.