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
Returns
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
Returns
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
listIListThe list to convert.
requiredLengthintThe required length of the result list.
startFromintThe starting index offset to begin parsing from.
Returns
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
parseMethodFunc<string, T, T>The function to parse each element to type T.
listIListThe list of elements to parse.
requiredLengthintThe required length of the result list.
Returns
- List<T>
A list of parsed numbers if successful and length matches; otherwise, null.
Type Parameters
TThe 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
parseMethodFunc<string, T, T>The function to parse each element to type T.
listIListThe list of elements to parse.
requiredLengthintThe required minimum length of the result list.
startFromTThe starting offset to begin parsing from.
Returns
- List<T>
A list of parsed numbers if successful; otherwise, null.
Type Parameters
TThe 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
parseMethodFunc<string, T, T>The function to parse each element to type T.
listIListThe list of elements to parse.
defaultValueTThe default value to use when parsing fails.
isRequiringAllNumbersboolIf 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
TThe 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
parseMethodFunc<string, T>The function to parse each element to type T.
listIList<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
TThe target numeric type.
UThe type of elements in the source list.