Class Price
- Namespace
- Ecng.ComponentModel
- Assembly
- Ecng.ComponentModel.dll
Represents a price with a specific value and type.
[DataContract]
public class Price : Equatable<Price>, ICloneable<Price>, ICloneable, IEquatable<Price>, IComparable, IPersistable, IOperable<Price>, IComparable<Price>, IFormattable
- Inheritance
-
Price
- Implements
- Inherited Members
- Extension Methods
Remarks
This class supports arithmetic operations, cloning, formatting, and persistence.
Constructors
Price()
Initializes a new instance of the Price class.
public Price()
Price(decimal, PriceTypes)
Initializes a new instance of the Price class with the specified value and type.
public Price(decimal value, PriceTypes type)
Parameters
value
decimalThe numeric value.
type
PriceTypesThe price type (measure).
Fields
LimitChar
Limit sign.
public const char LimitChar = 'l'
Field Value
PercentChar
Percent sign.
public const char PercentChar = '%'
Field Value
Properties
Type
Gets or sets the price type.
[DataMember]
public PriceTypes Type { get; set; }
Property Value
Value
Gets or sets the numeric value of the price.
[DataMember]
public decimal Value { get; set; }
Property Value
Methods
Clone()
Creates a copy of the current Price.
public override Price Clone()
Returns
CompareTo(Price)
Compares the current instance with another Price object.
public override int CompareTo(Price other)
Parameters
Returns
- int
A value less than zero if this instance is less than
other
, zero if they are equal, or a value greater than zero if this instance is greater thanother
.
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
obj
objectThe object to compare with this object.
Returns
- bool
true if the specified object is equal to the current object; otherwise, false.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
OnEquals(Price)
Determines equality between this instance and another instance of the same type.
protected override bool OnEquals(Price other)
Parameters
other
PriceAn object to compare with this instance.
Returns
- bool
true if the objects are equal; otherwise, false.
ToString()
public override string ToString()
Returns
ToString(string, IFormatProvider)
public string ToString(string format, IFormatProvider formatProvider)
Parameters
format
stringformatProvider
IFormatProvider
Returns
Operators
operator +(Price, Price)
Adds two Price instances.
public static Price operator +(Price v1, Price v2)
Parameters
Returns
- Price
The sum of the two prices.
operator /(Price, Price)
Divides one Price by another.
public static Price operator /(Price v1, Price v2)
Parameters
Returns
- Price
The quotient of the division.
operator ==(Price, Price)
Determines whether two Price objects are equal.
public static bool operator ==(Price v1, Price v2)
Parameters
Returns
- bool
true
if the prices are equal; otherwise,false
.
explicit operator decimal(Price)
public static explicit operator decimal(Price value)
Parameters
Returns
- decimal
The decimal representation of the price value.
Exceptions
- ArgumentNullException
Thrown when
value
is null.- InvalidOperationException
Thrown when the price type is Percent.
explicit operator double(Price)
public static explicit operator double(Price value)
Parameters
Returns
- double
The double representation of the price value.
Exceptions
- ArgumentNullException
Thrown when
value
is null.
explicit operator decimal?(Price)
public static explicit operator decimal?(Price value)
Parameters
Returns
- decimal?
The nullable decimal representation of the price value, or null if
value
is null.
explicit operator double?(Price)
public static explicit operator double?(Price value)
Parameters
Returns
- double?
The nullable double representation of the price value, or null if
value
is null.
operator >(Price, Price)
Determines whether one Price is greater than another.
public static bool operator >(Price v1, Price v2)
Parameters
Returns
- bool
true
ifv1
is greater thanv2
; otherwise,false
.
operator >=(Price, Price)
Determines whether one Price is greater than or equal to another.
public static bool operator >=(Price v1, Price v2)
Parameters
Returns
- bool
true
ifv1
is greater than or equal tov2
; otherwise,false
.
implicit operator Price(decimal)
public static implicit operator Price(decimal value)
Parameters
value
decimalThe decimal value to convert.
Returns
implicit operator Price(int)
public static implicit operator Price(int value)
Parameters
value
intThe integer value to convert.
Returns
operator !=(Price, Price)
Determines whether two Price objects are not equal.
public static bool operator !=(Price v1, Price v2)
Parameters
Returns
- bool
true
if the prices are not equal; otherwise,false
.
operator <(Price, Price)
Determines whether one Price is less than another.
public static bool operator <(Price v1, Price v2)
Parameters
Returns
- bool
true
ifv1
is less thanv2
; otherwise,false
.
operator <=(Price, Price)
Determines whether one Price is less than or equal to another.
public static bool operator <=(Price v1, Price v2)
Parameters
Returns
- bool
true
ifv1
is less than or equal tov2
; otherwise,false
.
operator *(Price, Price)
Multiplies two Price instances.
public static Price operator *(Price v1, Price v2)
Parameters
Returns
- Price
The product of the two prices.
operator -(Price, Price)
Subtracts one Price from another.
public static Price operator -(Price v1, Price v2)
Parameters
Returns
- Price
The difference of the two prices.
operator -(Price)
Returns a Price whose value is the negation of the specified price.
public static Price operator -(Price v)