Table of Contents

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 decimal

The numeric value.

type PriceTypes

The price type (measure).

Fields

LimitChar

Limit sign.

public const char LimitChar = 'l'

Field Value

char

PercentChar

Percent sign.

public const char PercentChar = '%'

Field Value

char

Properties

Type

Gets or sets the price type.

[DataMember]
public PriceTypes Type { get; set; }

Property Value

PriceTypes

Value

Gets or sets the numeric value of the price.

[DataMember]
public decimal Value { get; set; }

Property Value

decimal

Methods

Clone()

Creates a copy of the current Price.

public override Price Clone()

Returns

Price

A new Price instance that is a copy of this instance.

CompareTo(Price)

Compares the current instance with another Price object.

public override int CompareTo(Price other)

Parameters

other Price

The other Price to compare with.

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 than other.

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The 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 Price

An object to compare with this instance.

Returns

bool

true if the objects are equal; otherwise, false.

ToString()

public override string ToString()

Returns

string

ToString(string, IFormatProvider)

public string ToString(string format, IFormatProvider formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

Operators

operator +(Price, Price)

Adds two Price instances.

public static Price operator +(Price v1, Price v2)

Parameters

v1 Price

The first Price.

v2 Price

The second Price.

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

v1 Price

The numerator Price.

v2 Price

The denominator Price.

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

v1 Price

The first Price object.

v2 Price

The second Price object.

Returns

bool

true if the prices are equal; otherwise, false.

explicit operator decimal(Price)

Explicitly converts a Price to a decimal.

public static explicit operator decimal(Price value)

Parameters

value Price

The Price to convert.

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)

Explicitly converts a Price to a double.

public static explicit operator double(Price value)

Parameters

value Price

The Price to convert.

Returns

double

The double representation of the price value.

Exceptions

ArgumentNullException

Thrown when value is null.

explicit operator decimal?(Price)

Explicitly converts a Price to a nullable decimal.

public static explicit operator decimal?(Price value)

Parameters

value Price

The Price to convert.

Returns

decimal?

The nullable decimal representation of the price value, or null if value is null.

explicit operator double?(Price)

Explicitly converts a Price to a nullable double.

public static explicit operator double?(Price value)

Parameters

value Price

The Price to convert.

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

v1 Price

The first Price.

v2 Price

The second Price.

Returns

bool

true if v1 is greater than v2; 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

v1 Price

The first Price.

v2 Price

The second Price.

Returns

bool

true if v1 is greater than or equal to v2; otherwise, false.

implicit operator Price(decimal)

Implicitly converts a decimal to a Price.

public static implicit operator Price(decimal value)

Parameters

value decimal

The decimal value to convert.

Returns

Price

A new Price with the specified value.

implicit operator Price(int)

Implicitly converts an int to a Price.

public static implicit operator Price(int value)

Parameters

value int

The integer value to convert.

Returns

Price

A new Price with the specified value.

operator !=(Price, Price)

Determines whether two Price objects are not equal.

public static bool operator !=(Price v1, Price v2)

Parameters

v1 Price

The first Price object.

v2 Price

The second Price object.

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

v1 Price

The first Price.

v2 Price

The second Price.

Returns

bool

true if v1 is less than v2; 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

v1 Price

The first Price.

v2 Price

The second Price.

Returns

bool

true if v1 is less than or equal to v2; otherwise, false.

operator *(Price, Price)

Multiplies two Price instances.

public static Price operator *(Price v1, Price v2)

Parameters

v1 Price

The first Price.

v2 Price

The second Price.

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

v1 Price

The Price to subtract from.

v2 Price

The Price to subtract.

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)

Parameters

v Price

The Price to negate.

Returns

Price

A new Price with the opposite sign.