Class OperatorRegistry
- Namespace
- Ecng.ComponentModel
- Assembly
- Ecng.ComponentModel.dll
Provides a registry for operators to perform mathematical and comparison operations.
public static class OperatorRegistry
- Inheritance
-
OperatorRegistry
- Inherited Members
Methods
AddOperator<T>(IOperator<T>)
Adds an operator for the specified type.
public static void AddOperator<T>(IOperator<T> @operator)
Parameters
operatorIOperator<T>The operator to add.
Type Parameters
TThe type that the operator will handle.
Exceptions
- ArgumentNullException
Thrown when the
operatoris null.
GetOperator(Type)
Retrieves the operator associated with the specified type.
public static IOperator GetOperator(this Type type)
Parameters
typeTypeThe type for which to retrieve the operator.
Returns
- IOperator
The operator associated with the given type.
Exceptions
- InvalidOperationException
Thrown when no operator exists for the given type.
GetOperator<T>()
Retrieves the operator associated with the specified type parameter.
public static IOperator<T> GetOperator<T>()
Returns
- IOperator<T>
The operator associated with the given type.
Type Parameters
TThe type for which to retrieve the operator.
IsRegistered(Type)
Checks if an operator is registered for the specified type.
public static bool IsRegistered(Type type)
Parameters
typeTypeThe type to check for operator registration.
Returns
- bool
trueif an operator is registered; otherwise,false.
IsRegistered<T>()
Checks if an operator is registered for the specified type parameter.
public static bool IsRegistered<T>()
Returns
- bool
trueif an operator is registered; otherwise,false.
Type Parameters
TThe type to check for operator registration.
RemoveOperator<T>(IOperator<T>)
Removes the operator for the specified type.
public static void RemoveOperator<T>(IOperator<T> @operator)
Parameters
operatorIOperator<T>The operator instance to remove.
Type Parameters
TThe type whose operator is to be removed.
Exceptions
- ArgumentNullException
Thrown when the
operatoris null.
ThrowIfNegative(long, string)
Throws an exception if the specified long value is negative.
public static long ThrowIfNegative(this long value, string name)
Parameters
valuelongThe long value to check.
namestringThe name of the variable to include in the exception.
Returns
- long
The original value if it is not negative.
Exceptions
- ArgumentOutOfRangeException
Thrown when the value is negative.
ThrowIfNegative(long?, string)
Throws an exception if the specified nullable long value is negative.
public static long? ThrowIfNegative(this long? value, string name)
Parameters
valuelong?The nullable long value to check.
namestringThe name of the variable to include in the exception.
Returns
- long?
The original value if it is not negative; otherwise, null.