Extension Methods
Various extension methods are provided for several common .NET types.
Important
The ActiproSoftware.Extensions
namespace must be imported for the extensions described below to be available.
Assembly Extensions
The AssemblyExtensions type contains extension methods for the Assembly
type.
Member | Description |
---|---|
GetCopyrightMetadata | Returns the assembly's copyright metadata from AssemblyCopyrightAttribute . |
GetDescriptionMetadata | Returns the assembly's description metadata from AssemblyDescriptionAttribute . |
GetFileVersion | Returns the assembly's file Version from AssemblyFileVersionAttribute . |
GetInformationalVersion | Returns the assembly's informational version from AssemblyInformationalVersionAttribute . |
GetProductMetadata | Returns the assembly's product name metadata from AssemblyProductAttribute . |
GetTitleMetadata | Returns the assembly's title metadata from AssemblyTitleAttribute . |
DateTime Extensions
The DateTimeExtensions type contains extension methods for the DateTime
type.
Member | Description |
---|---|
IsToday | Returns whether the specified DateTime is today. |
IsWeekend | Returns whether the specified DateTime is on a weekend. |
ToString | Converts the value of a DateTime object to its equivalent string representation using the specified format pattern and optional culture-specific format information. |
DayOfWeek Extensions
The DayOfWeekExtensions type contains extension methods for the DayOfWeek
type.
Member | Description |
---|---|
IsWeekend | Returns whether the specified DayOfWeek is on a weekend. |
ToString | Converts the value of a DayOfWeek object to its equivalent string representation using the specified format pattern and optional culture-specific format information. |
Double Extensions
The DoubleExtensions type contains extension methods for the Double
type.
Member | Description |
---|---|
ClampToNonnegative | Returns the value clamped to a nonnegative number greater than or equal to 0.0 . Values less than 0.0 return 0.0 . All other values are unchanged. |
ClampToPercentage | Returns the value clamped to a percentage between 0.0 and 1.0 (inclusive). Values less than 0.0 return 0.0 , and values greater than 1.0 return 1.0 . All other values are unchanged. |
ClampToRange | Returns the value clamped between the specified minimum and maximum values. Values less than the minimum return the minumum, and values greater than the maximum return the maximum. All other values are unchanged. |
IsBetween | Returns whether a value is between the specified minimum and maximum (inclusive or exclusive). |
IsCloseTo | Returns whether a value is close enough with another value to be considered equal. |
IsGreaterThan | Determines whether the value is effectively greater than the comparison value. |
IsGreaterThanOrCloseTo | Determines whether the value is effectively greater than or equal to the comparison value. |
IsLessThan | Determines whether the value is effectively less than the comparison value. |
IsLessThanOrCloseTo | Determines whether the value is effectively less than or equal to the comparison value. |
IsNonnegative | Returns if a value is 0.0 or greater. |
IsPercentage | Returns if a value is between 0.0 and 1.0 (inclusive). |
IsZero | Determines whether the specified value is close enough to zero to be considered equal. |
NormalizeDegreeAngle | Returns a degree angle normalized to a value between 0.0 and 360.0 . Negative values are converted to their equivalent positive angle (e.g., -15.0 is normalized as 345.0 ). Values greater than 360.0 are normized to their equivalent position within the first 360.0 degrees (e.g., 460.0 is normalized as 100.0 ). |
Round | Returns a number rounded to a specified number of digits using a given RoundMode. |
RoundToMultiple | Returns a number rounded to the nearest multiple of another number (e.g., 13.0 rounded to the nearest multiple of 5.0 returns 15.0 ). |
Int32 Extensions
The Int32Extensions type contains extension methods for the Int32
type.
Member | Description |
---|---|
ClampToNonnegative | Returns the value clamped to a nonnegative number greater than or equal to 0 . Values less than 0 return 0 . All other values are unchanged. |
ClampToRange | Returns the value clamped between the specified minimum and maximum values. Values less than the minimum return the minumum, and values greater than the maximum return the maximum. All other values are unchanged. |
IsBetween | Returns whether a value is between the specified minimum and maximum (inclusive or exclusive). |
IsEven | Returns whether the value is an even number, including 0 . |
IsNonnegative | Returns if a value is 0 or greater. |
IsOdd | Returns whether the value is an odd number. |
IsPositive | Returns whether a value is inclusively between 1 ..Int32.MaxValue . |
RoundToMultiple | Returns a number rounded to the nearest multiple of another number (e.g., 13 rounded to the nearest multiple of 5 returns 15 ). |
List Extensions
The ListExtensions type contains extension methods for the IList<T>
type.
Member | Description |
---|---|
AddRange | Adds items to the end of the list. |
InsertRange | Inserts items in a list, starting at a specified index. |
RemoveAll | Removes all items that match a specified predicate. |
Object Extensions
The ObjectExtensions type contains extension methods for the Object
type.
Member | Description |
---|---|
TryConvertToDouble | Tries to convert an object to a Double value. To be successful, non-Double values must implement IConvertible.ToDouble . Alternatively, String values are processed using Double.TryParse . |