Class Utility
Some utility methods
Inherited Members
Namespace: SpiceSharp
Assembly: SpiceSharp.dll
Syntax
public static class Utility
Properties
Separator
Gets or sets the separator used when combining strings.
Declaration
public static string Separator { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
Between(int, string, int, int)
Throws an exception if the value is not in the specified range.
Declaration
public static int Between(this int value, string name, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| string | name | The name. |
| int | min | The minimum allowed value. |
| int | max | The maximum allowed value. |
Returns
| Type | Description |
|---|---|
| int | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not within bounds. |
CheckNodes(IReadOnlyList<string>, int)
Checks the number of specified nodes.
Declaration
public static IReadOnlyList<string> CheckNodes(this IReadOnlyList<string> nodes, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<string> | nodes | The nodes. |
| int | count | The number of expected nodes. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| NodeMismatchException | The number of nodes in |
Combine(string, string)
Combines a name with the specified appendix, using Separator.
Declaration
public static string Combine(this string name, string appendix)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name. |
| string | appendix | The appendix. |
Returns
| Type | Description |
|---|---|
| string | The combined string. |
Finite(double, string)
Requires the value to be both a number and finite.
Declaration
public static double Finite(this double value, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| string | name | The name of the property. |
Returns
| Type | Description |
|---|---|
| double | The value. |
FormatString(string, params object[])
Format a string using the current culture.
Declaration
public static string FormatString(this string format, params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| string | format | The formatting. |
| object[] | args | The arguments. |
Returns
| Type | Description |
|---|---|
| string | The formatted string. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| FormatException | Thrown if |
GreaterThan(double, string, double)
Throws an exception if the value is not greater than the specified limit.
Declaration
public static double GreaterThan(this double value, string name, double limit)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| string | name | The name. |
| double | limit | The limit. |
Returns
| Type | Description |
|---|---|
| double | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not greater than |
GreaterThan(int, string, int)
Throws an exception if the value is not greater than the specified limit.
Declaration
public static int GreaterThan(this int value, string name, int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| string | name | The name. |
| int | limit | The limit. |
Returns
| Type | Description |
|---|---|
| int | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not greater than |
GreaterThanOrEquals(double, string, double)
Throws an exception if the value is not greater than or equal to the specified limit.
Declaration
public static double GreaterThanOrEquals(this double value, string name, double limit)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| string | name | The name. |
| double | limit | The limit. |
Returns
| Type | Description |
|---|---|
| double | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not greater than or equal to |
GreaterThanOrEquals(int, string, int)
Throws an exception if the value is not greater than or equal to the specified limit.
Declaration
public static int GreaterThanOrEquals(this int value, string name, int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| string | name | The name. |
| int | limit | The limit. |
Returns
| Type | Description |
|---|---|
| int | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not greater than or equal to |
LessThan(double, string, double)
Throws an exception if the value is not less than the specified limit.
Declaration
public static double LessThan(this double value, string name, double limit)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| string | name | The name. |
| double | limit | The limit. |
Returns
| Type | Description |
|---|---|
| double | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not less than |
LessThan(int, string, int)
Throws an exception if the value is not less than the specified limit.
Declaration
public static int LessThan(this int value, string name, int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| string | name | The name. |
| int | limit | The limit. |
Returns
| Type | Description |
|---|---|
| int | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not less than |
LessThanOrEquals(double, string, double)
Throws an exception if the value is not less than or equal to the specified limit.
Declaration
public static double LessThanOrEquals(this double value, string name, double limit)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| string | name | The name. |
| double | limit | The limit. |
Returns
| Type | Description |
|---|---|
| double | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not less than or equal to the specified limit. |
LessThanOrEquals(int, string, int)
Throws an exception if the value is not less than or equal to the specified limit.
Declaration
public static int LessThanOrEquals(this int value, string name, int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| string | name | The name. |
| int | limit | The limit. |
Returns
| Type | Description |
|---|---|
| int | The original value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is not less than or equal to the specified limit. |
LowerLimit(double, object, string, double)
Specifies a lower limit for the value. If it is smaller, it is set to the limit value while raising a warning.
Declaration
public static double LowerLimit(this double value, object source, string name, double limit)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| object | source | The source. |
| string | name | The name. |
| double | limit | The limit. |
Returns
| Type | Description |
|---|---|
| double | The limited value. |
LowerLimit(int, object, string, int)
Specifies a lower limit for the value. If it is smaller, it is set to the limit value while raising a warning.
Declaration
public static int LowerLimit(this int value, object source, string name, int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| object | source | The source. |
| string | name | The name. |
| int | limit | The limit. |
Returns
| Type | Description |
|---|---|
| int | The limited value. |
ThrowIfEmpty<T>(IEnumerable<T>, string)
Throws an exception if the enumerable is null or empty.
Declaration
public static IEnumerable<T> ThrowIfEmpty<T>(this IEnumerable<T> source, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | source | The object. |
| string | name | The parameter name. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | The original object. |
Type Parameters
| Name | Description |
|---|---|
| T | The base type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
ThrowIfNotLength<T>(T[], string, int)
Throws an exception if the array does not have the specified length.
Declaration
public static T[] ThrowIfNotLength<T>(this T[] arguments, string name, int expected)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | arguments | The array. |
| string | name | The name of the parameter. |
| int | expected | The number of expected elements. |
Returns
| Type | Description |
|---|---|
| T[] | The array. |
Type Parameters
| Name | Description |
|---|---|
| T | The base type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Exepcted |
ThrowIfNotLength<T>(T[], string, int, int)
Throws an exception if the array does not have a length within range.
Declaration
public static T[] ThrowIfNotLength<T>(this T[] arguments, string name, int minimum, int maximum)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | arguments | The array. |
| string | name | The name of the parameter. |
| int | minimum | The minimum amount of arguments. |
| int | maximum | The maximum amount of arguments. |
Returns
| Type | Description |
|---|---|
| T[] | The array. |
Type Parameters
| Name | Description |
|---|---|
| T | The base type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Expected between |
ThrowIfNull<T>(T, string)
Throws an exception if the object is null.
Declaration
public static T ThrowIfNull<T>(this T source, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| T | source | The object. |
| string | name | The parameter name. |
Returns
| Type | Description |
|---|---|
| T | The original object. |
Type Parameters
| Name | Description |
|---|---|
| T | The base type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
UpperLimit(double, object, string, double)
Specifies an upper limit for the value. If it is larger, it is set to the limit value while raising a warning.
Declaration
public static double UpperLimit(this double value, object source, string name, double limit)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value. |
| object | source | The source. |
| string | name | The name. |
| double | limit | The limit. |
Returns
| Type | Description |
|---|---|
| double | The limited value. |
UpperLimit(int, object, string, int)
Specifies an upper limit for the value. If it is larger, it is set to the limit value while raising a warning.
Declaration
public static int UpperLimit(this int value, object source, string name, int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value. |
| object | source | The source. |
| string | name | The name. |
| int | limit | The limit. |
Returns
| Type | Description |
|---|---|
| int | The limited value. |