Class Utils
Contains helper functions, usable across the library.
public static class Utils
- Inheritance
-
Utils
- Inherited Members
Fields
C_BACKSLASH
public const char C_BACKSLASH = '\\'
Field Value
C_DOUBLE_QUOTE
public const char C_DOUBLE_QUOTE = '"'
Field Value
C_SINGLE_QUOTE
public const char C_SINGLE_QUOTE = '\''
Field Value
KEY_DECIMAL_DIGITS
public const string KEY_DECIMAL_DIGITS = "decimalDigits"
Field Value
KEY_LOCALE
public const string KEY_LOCALE = "locale"
Field Value
KEY_NAME
public const string KEY_NAME = "name"
Field Value
KEY_SYMBOL
public const string KEY_SYMBOL = "symbol"
Field Value
S_BACKSLASH
public const string S_BACKSLASH = "\\"
Field Value
S_DOUBLE_QUOTE
public const string S_DOUBLE_QUOTE = "\""
Field Value
S_SINGLE_QUOTE
public const string S_SINGLE_QUOTE = "'"
Field Value
Methods
ConvertToDouble(object)
public static double ConvertToDouble(object a)
Parameters
aobject
Returns
ConvertToLong(object)
public static long ConvertToLong(object a)
Parameters
aobject
Returns
FormatArbDateTime(object, Placeholder, CultureInfo)
public static string FormatArbDateTime(object value, Placeholder placeholder, CultureInfo culture)
Parameters
valueobjectplaceholderPlaceholdercultureCultureInfo
Returns
FormatArbNumber(ref int, object, Func<string, int, (object?, int)>, Placeholder, string, CultureInfo)
public static string FormatArbNumber(ref int placeholderIndex, object value, Func<string, int, (object?, int)> getPlaceholderValueFunc, Placeholder placeholder, string placeholderContentTail, CultureInfo culture)
Parameters
placeholderIndexintvalueobjectgetPlaceholderValueFuncFunc<string, int, (object, int)>placeholderPlaceholderplaceholderContentTailstringcultureCultureInfo
Returns
FormatArbString(ref int, object, Func<string, int, (object?, int)>, string, CultureInfo)
public static string FormatArbString(ref int placeholderIndex, object value, Func<string, int, (object?, int)> getPlaceholderValueFunc, string placeholderContentTail, CultureInfo culture)
Parameters
placeholderIndexintvalueobjectgetPlaceholderValueFuncFunc<string, int, (object, int)>placeholderContentTailstringcultureCultureInfo
Returns
FormatArbUnknownPlaceholder(ref int, object, Func<string, int, (object?, int)>, string, CultureInfo)
public static string FormatArbUnknownPlaceholder(ref int placeholderIndex, object value, Func<string, int, (object?, int)> getPlaceholderValueFunc, string placeholderContentTail, CultureInfo culture)
Parameters
placeholderIndexintvalueobjectgetPlaceholderValueFuncFunc<string, int, (object, int)>placeholderContentTailstringcultureCultureInfo
Returns
GetLeadingNonNegativeNumber(string, out int)
Extracts the number from a string when the string starts with a positive decimal number.
public static int GetLeadingNonNegativeNumber(string text, out int charsUsed)
Parameters
textstringThe text to extract the number from.
charsUsedintThe number of characters used from
textto parse as a number.
Returns
- int
The extracted number or -1 in the case when a number was not extracted.
IsBoxedIntegerNumber(object?)
Checks if the argument is of a integer type.
public static bool IsBoxedIntegerNumber(object? obj)
Parameters
objobjectAn object to check.
Returns
IsBoxedNumber(object?)
Checks if the argument is of a numeric type.
public static bool IsBoxedNumber(object? obj)
Parameters
objobjectAn object to check.
Returns
IsIdentifier(string?)
public static bool IsIdentifier(string? value)
Parameters
valuestring
Returns
IsIdentifierWithDots(string?)
public static bool IsIdentifierWithDots(string? value)
Parameters
valuestring
Returns
JsonEncode(string)
public static string JsonEncode(string value)
Parameters
valuestring
Returns
ParseDate(string, string)
public static DateTime ParseDate(string date, string format)
Parameters
Returns
ParseDateISO8601(string?)
public static DateTime? ParseDateISO8601(string? date)
Parameters
datestring
Returns
ReadFileFromDisk(string)
public static string? ReadFileFromDisk(string filename)
Parameters
filenamestring
Returns
ReadFileFromDisk(string, string?, string?)
public static string? ReadFileFromDisk(string filename, string? baseDirectory, string? baseDirectory2)
Parameters
Returns
ReadFileFromDisk(string, string?, string?, out string?)
public static string? ReadFileFromDisk(string filename, string? baseDirectory, string? baseDirectory2, out string? refFileName)
Parameters
Returns
ReadFileFromResource(Assembly, string)
public static string? ReadFileFromResource(Assembly assembly, string filename)
Parameters
Returns
ReadFileFromResource(Assembly, string, string?, string?)
public static string? ReadFileFromResource(Assembly assembly, string filename, string? baseDirectory, string? baseDirectory2)
Parameters
Returns
TryGetPropertyValue(object, string, out object?)
Retrieves the value of a public instance property, identified by its name, from the given object.
public static bool TryGetPropertyValue(object obj, string propertyName, out object? value)
Parameters
objobjectThe object to inspect.
propertyNamestringThe name of the property. The name is matched in a case-insensitive manner.
valueobjectReceives the value of the property when the lookup succeeds.
Returns
Remarks
The concrete type of obj is discovered at run time, which the trimmer cannot follow.
In a trimmed or NativeAOT application the properties of that type may have been removed, in which case this method
returns false even though the property exists in the source code. Use the overload that accepts
a Type to keep the lookup working.
TryGetPropertyValue(Type, object, string, out object?)
Retrieves the value of a public instance property, identified by its name, from the given object.
This overload is safe to use in trimmed and NativeAOT applications: the trimmer is told to preserve the
public properties of type, so the lookup keeps working. Pass a type that is known at compile
time (typically typeof(T) of a generic parameter that carries the same annotation) rather than the result
of GetType(), which the trimmer cannot track back to a concrete type.
public static bool TryGetPropertyValue(Type type, object obj, string propertyName, out object? value)
Parameters
typeTypeThe type whose public instance properties are searched.
objobjectThe object to read the property value from.
propertyNamestringThe name of the property. The name is matched in a case-insensitive manner.
valueobjectReceives the value of the property when the lookup succeeds.
Returns
UnescapeString(string, bool)
Decodes escaping used in JSON and TOML strings.
public static string UnescapeString(string value, bool throwOnInvalidEscapeSequence = false)
Parameters
valuestringoriginal string to decode.
throwOnInvalidEscapeSequenceboolSpecifies whether an exception should be thrown if an escape sequence (? where ? is an unrecognized moniker) is not recognized.
Returns
- string
a decoded string.