LB.Utility
1.0.41
dotnet add package LB.Utility --version 1.0.41
NuGet\Install-Package LB.Utility -Version 1.0.41
<PackageReference Include="LB.Utility" Version="1.0.41" />
<PackageVersion Include="LB.Utility" Version="1.0.41" />
<PackageReference Include="LB.Utility" />
paket add LB.Utility --version 1.0.41
#r "nuget: LB.Utility, 1.0.41"
#:package LB.Utility@1.0.41
#addin nuget:?package=LB.Utility&version=1.0.41
#tool nuget:?package=LB.Utility&version=1.0.41
A set of extensions and helper methods that I use across all of my projects.
LB.Utility
class Pagination
A class to calculate pagination for lists
Pagination()
Constructs a default pagination object
Pagination(Int32 currentPage, Int32 totalItems, Int32 itemsPerPage, Int32 maxPagesToDisplay)
Constructs a pagination object
Parameters
| Name | Type | Description |
|---|---|---|
currentPage |
Int32 |
The current page |
totalItems |
Int32 |
The total number of items |
itemsPerPage |
Int32 |
How many items to display per page |
maxPagesToDisplay |
Int32 |
The number of pages to display |
LB.Utility.Attributes
class EnumAliasAttribute
Used to decorate an enumerator value with an alias that the value can be selected by
EnumAliasAttribute(String alias)
Constructs the EnumAliasAttribute with the provided alias
Parameters
| Name | Type | Description |
|---|---|---|
alias |
String |
The alias to know the enum value by |
EnumAliasAttribute(String[] aliases)
Constructs the EnumAliasAttribute with the provided aliases
Parameters
| Name | Type | Description |
|---|---|---|
aliases |
String[] |
A list of aliases to know the enum value by |
GetEnumValue<T>(Char value)
Will attempt to get the value of the enum by the name or alias
Type Parameters
| Name | Description |
|---|---|
T |
The enumerator type |
Parameters
| Name | Type | Description |
|---|---|---|
value |
Char |
The character value of the enum or its alias |
Returns
T
The enum value if it exists, otherwise null
GetEnumValue<T>(String value)
Will attempt to get the value of the enum by the name or alias
Type Parameters
| Name | Description |
|---|---|
T |
The enumerator type |
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
The string value of the enum or its alias |
Returns
T
The enum value if it exists, otherwise null
LB.Utility.Collections
class InsensitiveDictionary
A case insensitive Dictionary<String, T>
InsensitiveDictionary()
Constructs an InsensitiveDictionary
Add(KeyValuePair item)
Add a new item to the dictionary from the provided
Parameters
| Name | Type | Description |
|---|---|---|
item |
KeyValuePair |
The KeyValuePair to add |
LB.Utility.Extensions
class CharacterExtensions
Extensions for the Char data type
IsVowel(Char extended)
Determines if the character is a vowel in English
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Char |
The character to check |
Returns
Boolean
True if the character is a vowel
Remarks
Only works with English
class CollectionExtensions
Extension methods for Collections
GetHalves<T>(IEnumerable extended)
Divides the list into even parts
Type Parameters
| Name | Description |
|---|---|
T |
The type of the IEnumerable |
Parameters
| Name | Type | Description |
|---|---|---|
extended |
IEnumerable |
The list to split |
Returns
IEnumerable
Two lists created from dividing the list in half
Remarks
For odd length lists, the first half will have on more element
GetValue<K, V>(IDictionary extended, K key, V defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
IDictionary |
|
key |
K |
|
defaultValue |
V |
Returns
V
IsNullOrEmpty<T>(IEnumerable extended)
Returns true if the collection is null or has no items
Type Parameters
| Name | Description |
|---|---|
T |
The type of the IEnumerable |
Parameters
| Name | Type | Description |
|---|---|---|
extended |
IEnumerable |
The list to check |
Returns
Boolean
True if the list is null or has no elements
NotNull<T>(IEnumerable extended)
Returns all non null values from the collection
Type Parameters
| Name | Description |
|---|---|
T |
The type of the IEnumerable |
Parameters
| Name | Type | Description |
|---|---|---|
extended |
IEnumerable |
The IEnumerable to process |
Returns
IEnumerable
A IEnumerable with all null values removed
NotNullOrWhitespace(IEnumerable extended)
Returns all values that are not null, empty, or whitespace.
Parameters
| Name | Type | Description |
|---|---|---|
extended |
IEnumerable |
The collection to search |
Returns
IEnumerable
A list excluding null, empty, or whitespace elements
TrimAll(IEnumerable extended)
Trim all values of whitespace
Parameters
| Name | Type | Description |
|---|---|---|
extended |
IEnumerable |
The collection to loop through |
Returns
IEnumerable
The collection with whitespace trimmed from each element
class DateExtensions
Extension for Date data types
ToDateTime<T>(T extended)
Attempts to convert the object to a date time value
Type Parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
extended |
T |
Returns
Nullable<DateTime>
The object as a date time or null if the conversion fails
ToDateTime<T>(T extended, Nullable<DateTime> defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
T |
|
defaultValue |
Nullable<DateTime> |
Returns
Nullable<DateTime>
Truncate(DateTime extended, DatePart part)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
DateTime |
|
part |
DatePart |
Returns
DateTime
enum DatePart
The parts of a date time
class EnumExtensions
Extensions for enum types
GetAttributeOfType<T>(Enum value)
Gets an attributes associated with the enum value
Type Parameters
| Name | Description |
|---|---|
T |
The enum type |
Parameters
| Name | Type | Description |
|---|---|---|
value |
Enum |
The enum type value |
Returns
T
The attribute if it exists, otherwise null
GetDisplay(Enum value)
Gets the DisplayAttribute if one exists for the value
Parameters
| Name | Type | Description |
|---|---|---|
value |
Enum |
The value to inspect |
Returns
DisplayAttribute
The DisplayAttribute if it exists, otherwise null
GetDisplayDescription(Enum value)
Gets the Display Description value if the value has the DisplayAttribute
Parameters
| Name | Type | Description |
|---|---|---|
value |
Enum |
The value to inspect |
Returns
String
The Display Description or value.ToString()
GetDisplayName(Enum value)
Gets the Display Name value if the value has the DisplayAttribute
Parameters
| Name | Type | Description |
|---|---|---|
value |
Enum |
The value to inspect |
Returns
String
The Display Name or value.ToString()
class GenericsExtensions
Extensions using generics
GetValueOrDefault<T>(T extended, T defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
T |
|
defaultValue |
T |
Returns
T
In<T>(T extended, T[] list)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
T |
|
list |
T[] |
Returns
Boolean
In<T>(T extended, IEqualityComparer comparer, T[] list)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
T |
|
comparer |
IEqualityComparer |
|
list |
T[] |
Returns
Boolean
In<T>(T extended, Func comparer, T[] list)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
T |
|
comparer |
Func |
|
list |
T[] |
Returns
Boolean
class NumericExtensions
Extensions for numeric data types
Between(Int32 extended, Int32 min, Int32 max)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
|
min |
Int32 |
|
max |
Int32 |
Returns
Int32
IsEven(Int32 extended)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
Returns
Boolean
IsOdd(Int32 extended)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
Returns
Boolean
ToDataSize(Int32 extended)
Returns the integer as a data size String
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
The integer to format |
Returns
String
The integer as a data size String
ToDataSize(Int64 extended)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int64 |
Returns
String
ToDataSize(Int64 extended, String format)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int64 |
|
format |
String |
Returns
String
ToDataSize(UInt64 extended, String format)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
UInt64 |
|
format |
String |
Returns
String
ToFeetInches(Int32 extended, String format, IFormatProvider provider)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
|
format |
String |
|
provider |
IFormatProvider |
Returns
String
ToFeetInches(Double extended, String format, IFormatProvider provider)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Double |
|
format |
String |
|
provider |
IFormatProvider |
Returns
String
ToOrdinal(Int32 extended)
Adds the ordinal suffix to an
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
The to add the suffix to |
Returns
String
The orginal with it's appropriate suffix
Remarks
Currently only supports English
ToOrdinal(Int32 extended, Boolean superscript)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
|
superscript |
Boolean |
Returns
String
ToRomanNumerals(Int32 extended)
Returns the Roman Numeral equivalent of the provided integer
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
Returns
String
Remarks
Roman numerals only support numbers between 1 and 4000. Numbers outside of this range are returned as Arabic numbers.
ToText(Int32 extended)
Converts an to its numeric word
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int32 |
The to convert |
Returns
String
The numeric word for the
Remarks
Currently only supports English
ToText(Int64 extended)
Converts an to its numeric word
Parameters
| Name | Type | Description |
|---|---|---|
extended |
Int64 |
The to convert |
Returns
String
The numeric word for the
Remarks
Currently only supports English
class StringBuilderExtensions
Extenions methods for the StringBuilder type
IsNullOrEmpty(StringBuilder extended)
Returns true if the string builder is empty
Parameters
| Name | Type | Description |
|---|---|---|
extended |
StringBuilder |
The to check |
Returns
Boolean
true if the value parameter is null or an empty string (""); otherwise, false.
IsNullOrWhitespace(StringBuilder extended)
Returns true if the string builder is empty
Parameters
| Name | Type | Description |
|---|---|---|
extended |
StringBuilder |
The to check |
Returns
Boolean
true if the value parameter is null or System.String.Empty, or if value consists exclusively of white-space characters; otherwise, false.
class StringExtensions
Extension methods for the String data type
AOrAn(String value)
Determines if the indeterminite article before the string should be A or An
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
The string to evaluate |
Returns
String
The prefixed with an "a" or "an".
Remarks
Only works with English
GetValueOrDefault(String extended)
Returns an empty string if extended is null
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
The string to evaluate |
Returns
String
If the string is null, an ; otherwise,
GetValueOrDefault(String extended, String defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
defaultValue |
String |
Returns
String
HasValue(String extended, Boolean allowWhitespace)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
allowWhitespace |
Boolean |
Returns
Boolean
IsNullOrEmpty(String extended)
Indicates whether a specified string is null or empty.
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
The string to evaluate |
Returns
Boolean
true if the value parameter is null or .
IsNullOrEmpty(String extended, String defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
defaultValue |
String |
Returns
String
IsNullOrWhitespace(String extended)
Indicates whether a specified string is null, empty, or consists only of white-space characters.
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
The string to evaluate |
Returns
Boolean
true if the value parameter is null or , or if value consists exclusively of white-space characters.
IsNullOrWhitespace(String extended, String defaultValue)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
defaultValue |
String |
Returns
String
RemoveAll(String extended, String[] items)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
items |
String[] |
Returns
String
RemoveAll(String extended, Char[] items)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
items |
Char[] |
Returns
String
RemoveArticles(String extended)
Remove articles from the beginning of strings
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
The string to remove articles from |
Returns
String
The string minus any articles found at the beginning
RemoveFirst(String extended, String value)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
value |
String |
Returns
String
RemoveLast(String extended, String value)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
value |
String |
Returns
String
Right(String extended, Int32 characters)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
characters |
Int32 |
Returns
String
Split(String extended, Int32 partSize)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
partSize |
Int32 |
Returns
List
Split(String extended, Char separator, Char escapeCharacter)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
separator |
Char |
|
escapeCharacter |
Char |
Returns
IEnumerable
Split(String extended, Char separator, Char escapeCharacter, Boolean removeEmptyEntries)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
separator |
Char |
|
escapeCharacter |
Char |
|
removeEmptyEntries |
Boolean |
Returns
IEnumerable
SplitOnCaps(String extended, Char replacement)
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
|
replacement |
Char |
Returns
String
ToHTMLId(String extended)
Converts a string to a valid html id by removing all non-alphanumeric characters
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
The string to convert |
Returns
String
ToTitleCase(String extended)
Converts a string to title case
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
Returns
String
Val(String extended)
Returns the numbers contained in a string as a numeric value of appropriate type.
Parameters
| Name | Type | Description |
|---|---|---|
extended |
String |
Returns
Double
class TypeExtensions
Extension methods for the data type
IsNumeric(Type type)
Returns true if the type is numeric
Parameters
| Name | Type | Description |
|---|---|---|
type |
Type |
Returns
Boolean
class UnitConversionExtensions
Unit Conversion helpers
CelsiusToFarenheit(Decimal celsius)
Converts Celsius to Farenheit
Parameters
| Name | Type | Description |
|---|---|---|
celsius |
Decimal |
Degrees Celsius |
Returns
Decimal
Degrees Farenheit
CentimetersToInches(Decimal cm)
Converts Centimeters to Inches
Parameters
| Name | Type | Description |
|---|---|---|
cm |
Decimal |
The total centimeters |
Returns
Decimal
The number of Inches
FarenheitToCelsius(Decimal farenheit)
Converts Farenheit to Celsius
Parameters
| Name | Type | Description |
|---|---|---|
farenheit |
Decimal |
Degrees Farenheit |
Returns
Decimal
Degrees Celsius
InchesToCentimeters(Decimal inches)
Converts Inches to Centimeters
Parameters
| Name | Type | Description |
|---|---|---|
inches |
Decimal |
The total inches |
Returns
Decimal
The number of Centimeters
LB.Utility.Random
class PseudoRNG
A crossplatform pseudo random number generator
PseudoRNG(String seed)
Creates a PCG32 RNG
Parameters
| Name | Type | Description |
|---|---|---|
seed |
String |
Initial state seed |
PseudoRNG(UInt64 seed, UInt64 sequence)
Creates a PCG32 RNG
Parameters
| Name | Type | Description |
|---|---|---|
seed |
UInt64 |
Initial state seed |
sequence |
UInt64 |
Stream selector (must be odd internally) |
NextBool()
Returns
Boolean
NextBytes(Span buffer)
Parameters
| Name | Type | Description |
|---|---|---|
buffer |
Span |
NextDouble()
Returns a double in [0, 1).
Returns
Double
NextInt32()
Returns a uniformly distributed Int32 (full range).
Returns
Int32
NextInt32(Int32 maxExclusive)
Returns an Int32 in [0, maxExclusive).
Parameters
| Name | Type | Description |
|---|---|---|
maxExclusive |
Int32 |
Returns
Int32
NextInt32(Int32 minInclusive, Int32 maxExclusive)
Parameters
| Name | Type | Description |
|---|---|---|
minInclusive |
Int32 |
|
maxExclusive |
Int32 |
Returns
Int32
NextInt64()
Returns a uniformly distributed Int64 (full range).
Returns
Int64
NextInt64(Int64 maxExclusive)
Returns an Int64 in [0, maxExclusive).
Parameters
| Name | Type | Description |
|---|---|---|
maxExclusive |
Int64 |
Returns
Int64
NextInt64(Int64 minInclusive, Int64 maxExclusive)
Parameters
| Name | Type | Description |
|---|---|---|
minInclusive |
Int64 |
|
maxExclusive |
Int64 |
Returns
Int64
NextUInt32()
Returns a uniformly distributed 32-bit unsigned integer.
Returns
UInt32
NextUInt32(UInt32 maxExclusive)
Returns an Int32 in [0, maxExclusive).
Parameters
| Name | Type | Description |
|---|---|---|
maxExclusive |
UInt32 |
Returns
UInt32
NextUInt32(UInt32 minInclusive, UInt32 maxExclusive)
Parameters
| Name | Type | Description |
|---|---|---|
minInclusive |
UInt32 |
|
maxExclusive |
UInt32 |
Returns
UInt32
NextUInt64()
Returns a uniformly distributed 32-bit unsigned integer.
Returns
UInt64
NextUInt64(UInt64 maxExclusive)
Parameters
| Name | Type | Description |
|---|---|---|
maxExclusive |
UInt64 |
Returns
UInt64
NextUInt64(UInt64 minInclusive, UInt64 maxExclusive)
Parameters
| Name | Type | Description |
|---|---|---|
minInclusive |
UInt64 |
|
maxExclusive |
UInt64 |
Returns
UInt64
LB.Utility.Types
struct Fraction
Fraction(Double d)
Parameters
| Name | Type | Description |
|---|---|---|
d |
Double |
Fraction(Int32 w, Int32 n, Int32 d)
Parameters
| Name | Type | Description |
|---|---|---|
w |
Int32 |
|
n |
Int32 |
|
d |
Int32 |
Equals(Object obj)
Parameters
| Name | Type | Description |
|---|---|---|
obj |
Object |
Returns
Boolean
GCD(Int32 numerator, Int32 denominator)
Parameters
| Name | Type | Description |
|---|---|---|
numerator |
Int32 |
|
denominator |
Int32 |
Returns
Int32
LCM(Int32 a, Int32 b)
Parameters
| Name | Type | Description |
|---|---|---|
a |
Int32 |
|
b |
Int32 |
Returns
Int32
ToString()
Returns
String
ToString(String format)
Parameters
| Name | Type | Description |
|---|---|---|
format |
String |
Returns
String
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.