Provides extension methods that apply to all types.
byte[] | |
Decrypts data encrypted with Ut.AesEncrypt(byte[], byte[]). |
byte[] | |
Encrypts bytes using AES in CBC mode. |
void | Apply<TSource>(this TSource source, Action<TSource> action) |
Executes the specified action with the specified argument. |
TResult | Apply<TSource, TResult>(this TSource source, Func<TSource, TResult> func) |
Executes the specified function with the specified argument. |
void | Apply<TSource1, TSource2>(this ValueTuple<TSource1, TSource2> source, Action<TSource1, TSource2> action) |
Executes the specified action with the specified tuple argument. |
TResult | Apply<TSource1, TSource2, TResult>(this ValueTuple<TSource1, TSource2> source, Func<TSource1, TSource2, TResult> func) |
Executes the specified function with the specified tuple argument. |
T[] | |
Concatenates any number of arrays. |
int | |
Computes a hash value from an array of elements. |
int | |
void | Assert(bool assertion, string message = null) |
Checks the specified condition and causes the debugger to break if it is false. Throws an Exception afterwards. |
void | AssertAll<T>(IEnumerable<T> collection, Func<T, bool> assertion, string message = null) |
int | BytesToInt(byte[] buffer, int index, bool bigEndian = false) |
Converts the bytes at the specified index within the specified buffer to
a 32-bit signed integer. |
long | BytesToLong(byte[] buffer, int index, bool bigEndian = false) |
Converts the bytes at the specified index within the specified buffer to
a 64-bit signed integer. |
short | BytesToShort(byte[] buffer, int index, bool bigEndian = false) |
Converts the bytes at the specified index within the specified buffer to
a 16-bit signed integer. |
uint | BytesToUInt(byte[] buffer, int index, bool bigEndian = false) |
Converts the bytes at the specified index within the specified buffer to
a 32-bit unsigned integer. |
ulong | BytesToULong(byte[] buffer, int index, bool bigEndian = false) |
Converts the bytes at the specified index within the specified buffer to
a 64-bit unsigned integer. |
ushort | |
Converts the bytes at the specified index within the specified buffer to
a 16-bit unsigned integer. |
Delegate | |
Creates a delegate using Action<,*> or Func<,*> depending on the number of parameters of the
specified method. |
void | Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> source, out TKey key, out TValue value) | Allows the deconstruction of KeyValuePairs into separate variables. |
IEnumerable<ValueTuple<T, DiffOp>> | Diff<T>(IEnumerable<T> old, IEnumerable<T> new, IEqualityComparer<T> comparer = null, Func<T, bool> predicate = null, Func<IEnumerable<T>, IEnumerable<T>, IEnumerable<ValueTuple<T, DiffOp>>> postProcessor = null) |
Computes a representation of the differences between old and new using
the specified options. |
string | |
Formats an entire CSV row, escaping cell values where required. See Remarks. |
string | |
int | | Calculates the greatest common divisor of a and b. |
uint | |
long | |
ulong | |
TAttribute | |
Returns the single custom attribute of the specified TAttribute type that is attached
to the declaration of the enum value represented by enumValue, or null if there is
no such attribute. |
TAttribute[] | |
Returns the set of custom attributes of the specified TAttribute type that are attached
to the declaration of the enum value represented by enumValue. |
T | | Searches the specified object’s type for a field of the specified name and returns that field’s value. |
string | |
Finds the longest substring that all of the specified input strings contain. |
bool | | Returns true if this value is equal to the default value for this type. |
KeyValuePair<TKey, TValue> | | Allows the use of type inference when creating .NET’s KeyValuePair<TK,TV>. |
Action | |
Allows the use of C#’s powerful type inference when declaring local lambdas whose delegate type doesn't make
any difference. |
Action<T> | |
Func<TResult> | Lambda<TResult>(Func<TResult> method) |
Action<T1, T2> | Lambda<T1, T2>(Action<T1, T2> method) |
Func<T, TResult> | Lambda<T, TResult>(Func<T, TResult> method) |
Action<T1, T2, T3> | Lambda<T1, T2, T3>(Action<T1, T2, T3> method) |
Func<T1, T2, TResult> | Lambda<T1, T2, TResult>(Func<T1, T2, TResult> method) |
Action<T1, T2, T3, T4> | Lambda<T1, T2, T3, T4>(Action<T1, T2, T3, T4> method) |
Func<T1, T2, T3, TResult> | Lambda<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> method) |
Action<T1, T2, T3, T4, T5> | Lambda<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> method) |
Func<T1, T2, T3, T4, TResult> | Lambda<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult> method) |
Func<T1, T2, T3, T4, T5, TResult> | Lambda<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult> method) |
T | | Returns the largest of all arguments passed in. Uses the Linq .Max extension method to do the work. |
T | | Returns the larger of the two IComparable values. If the values are equal, returns the first one. |
T | Max<T>(T val1, T val2, T val3) | Returns the larger of the three IComparable values. If two values are equal, returns the earlier one. |
string | |
Reads the specified file and computes the MD5 hash function from its contents. |
T | | Returns the smallest of all arguments passed in. Uses the Linq .Min extension method to do the work. |
T | | Returns the smaller of the two IComparable values. If the values are equal, returns the first one. |
T | Min<T>(T val1, T val2, T val3) | Returns the smaller of the three IComparable values. If two values are equal, returns the earlier one. |
T[] | |
Returns the parameters as a new array. |
T[] | NewArray<T>(int size, Func<int, T> initialiser) |
Instantiates a fully-initialized array with the specified dimensions. |
T[][] | NewArray<T>(int size1, int size2, Func<int, int, T> initialiser = null) |
Instantiates a fully-initialized rectangular jagged array with the specified dimensions. |
T[][][] | NewArray<T>(int size1, int size2, int size3, Func<int, int, int, T> initialiser = null) |
Instantiates a fully-initialized "rectangular" jagged array with the specified dimensions. |
TInput? | | Turns the specified value into a nullable value. |
TResult | | Returns null if the input is null, otherwise the result of the specified lambda when applied to the input. |
TResult? | NullOr<TInput, TResult>(this TInput input, FuncClass<TInput, TResult?> lambda) |
TResult? | |
TResult | |
TResult? | NullOr<TInput, TResult>(this TInput? input, FuncStruct<TInput, TResult?> lambda) |
TResult? | |
TResult | OnException<TException, TResult>(Func<TResult> func, Func<TException, TResult> onException) |
Evaluates the specified code and returns its result. If the code throws an exception of the specified type, runs
onException instead. |
TResult | |
Evaluates the specified code and returns its result. If the code throws any exceptions, returns default instead. |
TResult | |
Evaluates the specified code and returns its result. If the code throws TException, returns
default instead. Doesn't catch any other exceptions. |
bool | |
Evaluates the specified code. If the code throws any exceptions, catches and suppresses them. |
bool | |
Evaluates the specified code and returns its result. If the code throws TException, catches
and suppresses it. Doesn't catch any other exceptions. |
void | OnExceptionRetry(Action action, int attempts = 3, int delayMs = 333, Action onException = null) |
Evaluates the specified code. If the code throws any exceptions, retries the specified number of times. The final
attempt is executed without any exception handlers. |
void | OnExceptionRetry<TException>(Action action, int attempts = 3, int delayMs = 333) |
Evaluates the specified code. If the code throws TException, retries the specified number
of times. The final attempt is executed without any exception handlers. |
TResult | OnExceptionRetry<TResult>(Func<TResult> func, int attempts = 3, int delayMs = 333, Action onException = null) |
Evaluates the specified code and returns its result. If the code throws any exceptions, retries the specified
number of times. The final attempt is executed without any exception handlers. |
TResult | OnExceptionRetry<TResult, TException>(Func<TResult> func, int attempts = 3, int delayMs = 333) |
Evaluates the specified code and returns its result. If the code throws TException, retries
the specified number of times. The final attempt is executed without any exception handlers. |
TResult | |
Evaluates the specified code and returns its result. If the code throws any exceptions, retries the specified
number of times. If the code still throws on the final attempt, returns default
instead. |
TResult | |
Evaluates the specified code and returns its result. If the code throws TException, retries
the specified number of times. If the code still throws TException on the final attempt,
returns default instead. Doesn't catch any other exceptions. |
bool | |
Evaluates the specified code. If the code throws any exceptions, retries the specified number of times. If the
code still throws on the final attempt, suppresses the exception. |
bool | |
Evaluates the specified code. If the code throws TException, retries the specified number
of times. If the code still throws TException on the final attempt, suppresses the
exception. Doesn't catch any other exceptions. |
void | |
Runs all of the specified actions in parallel, each in a thread of its own. |
void | Parallel(int maxSimultaneous, params Action<int>[] actions) |
Runs the specified actions partly in parallel by using no more than the specified maximum number of threads. |
void | |
Runs the specified action in parallel for each item in the input collection. |
void | |
void | ParallelForEach<T>(this IEnumerable<T> items, int maxSimultaneous, Action<T> action) |
Runs the specified action in parallel for each item in the input collection, using no more than the specified
maximum number of threads. |
void | ParallelForEach<T>(this IEnumerable<T> items, int maxSimultaneous, Action<T, int> action) |
IEnumerable<TResult> | ParallelSelect<TSource, TResult>(this IEnumerable<TSource> items, Func<TSource, TResult> selector) |
Runs the specified function in parallel for each item in the input collection and returns a collection
containing the results of the function calls. |
IEnumerable<TResult> | ParallelSelect<TSource, TResult>(this IEnumerable<TSource> items, int maxSimultaneous, Func<TSource, TResult> selector) |
IEnumerable<TResult> | ParallelSelectMany<TSource, TResult>(this IEnumerable<TSource> items, Func<TSource, IEnumerable<TResult>> selector) |
Runs the specified function in parallel for each item in the input collection and returns a collection
containing the concatenation of all the results of the function calls. |
IEnumerable<TResult> | ParallelSelectMany<TSource, TResult>(this IEnumerable<TSource> items, int maxSimultaneous, Func<TSource, IEnumerable<TResult>> selector) |
IEnumerable<string[]> | ParseCsv(TextReader reader, int minColumns = 0) |
Parses text from the reader as CSV. See Remarks. |
IEnumerable<string[]> | ParseCsv(string content, int minColumns = 0) | Parses content as CSV. For details see Ut.ParseCsv(TextReader, int). |
IEnumerable<string[]> | |
Parses the file at path as CSV. For details see Ut.ParseCsv(TextReader, int). |
DateTime? | |
Returns the date/time stamp represented by the specified string, or null if the string does not represent a
valid date/time stamp. |
double? | |
Returns the floating-point number represented by the specified string, or null if the string does not
represent a valid double-precision floating-point number. |
T? | ParseEnum<T>(string value, bool ignoreCase = false) |
Returns the enum value represented by the specified string, or null if the string does not represent a valid
enum value. |
int? | |
Returns the integer represented by the specified string, or null if the string does not represent a valid
32-bit integer. |
long? | |
Returns the integer represented by the specified string, or null if the string does not represent a valid
64-bit integer. |
IEnumerable<double> | Range(double start, double end, double step) |
Generates a sequence of floating-point numbers within a specified range. |
IEnumerable<T> | |
Given a set of values and a function that returns true when given this set, will efficiently remove items from
this set which are not essential for making the function return true. The relative order of items is
preserved. This method cannot generally guarantee that the result is optimal, but for some types of functions
the result will be guaranteed optimal. |
void | RunMain(Action main, Action<Exception> onUnhandledMain, Action<Exception> onUnhandledThread = null) |
Execute the core of the application. In debug mode, exceptions are passed through untouched. In release mode, all
exceptions are caught, including those on other threads, and passed on to the specified handlers. Also, the main thread
is given the name "Main". |
int | RunMain(Func<int> main, Func<Exception, int> onUnhandledMain, Action<Exception> onUnhandledThread = null) |
string | |
Reads the specified file and computes the SHA1 hash function from its contents. |
string | |
Converts file size in bytes to a string that uses KB, MB, GB or TB. |
void | Swap<T>(ref T one, ref T two) | Swaps the values of the specified two variables. |
void | |
Queues the specified action to be executed on the thread pool. This is just a shortcut for
ThreadPool.QueueUserWorkItem , and also does not require the method to accept a parameter (which has
been useless ever since C# gained support for lambdas). |
double | |
Starts / resets a simple performance timer. Returns the number of seconds elapsed since the last call to Ut.Tic(), or zero if this is the first call. See also Ut.Toc(). |
double | | Returns the number of seconds elapsed since the last call to Ut.Tic(). |
string | | Generates a representation of the specified byte array as hexadecimal numbers (“hexdump”). |
string | | Generates a representation of the specified uint array as hexadecimal numbers (“hexdump”). |
string | ToHex(this IEnumerable<byte> data, int spacesEvery = 0) | Generates a representation of the specified byte sequence as hexadecimal numbers (“hexdump”). |
string | | Returns the version of the entry assembly (the .exe file) in a standard format. |
void | WaitSharingVio(Action action, TimeSpan? maximum = null, Action onSharingVio = null) |
Executes the specified action. If the action results in a file sharing violation exception, the action will be
repeatedly retried after a short delay (which increases after every failed attempt). |
T | WaitSharingVio<T>(Func<T> func, TimeSpan? maximum = null, Action onSharingVio = null) |
Executes the specified function. If the function results in a file sharing violation exception, the function
will be repeatedly retried after a short delay (which increases after every failed attempt). |